-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
1447 lines (1102 loc) · 57.2 KB
/
main.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
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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#from Rhino.Geometry import *
from typing import List
import math
import time
import os
import matplotlib.pyplot as plt
import numpy
class Vector3d:
def __init__(self, x, y, z):
self.X = x
self.Y = y
self.Z = z
def VectorAngle(self, vector1, vector2):
a = vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z
b = vector1.Length * vector2.Length
return math.acos(a/b)
@property
def Length(self):
return math.sqrt(self.X ** 2 + self.Y ** 2 + self.Z ** 2)
###########################
class OpaqueMaterial:
def __init__(self, name="Default Concrete", conductivity=2.0, density=2400, reflectivity=0.5, absorbance=0.3,
heat_capacity=1.0):
self.name = name
self.conductivity = conductivity
self.density = density
self.reflectivity = reflectivity
self.absorbance = absorbance
self.heat_capacity = heat_capacity
def GetThermalResistance(self, thickness):
return thickness / self.conductivity
def __str__(self):
return self.name
#====================================#
class OpaqueConstructionMaterial:
def __init__(self, material: OpaqueMaterial, thickness = 0.1, area = 1, temperature = 20):
self.material = material
self.thickness = thickness
self.area = area
self.temperature = temperature
self.resistance = self.material.GetThermalResistance(self.thickness)
self.q = self.temperature * self.area * self.thickness * self.material.density * self.material.heat_capacity
#====================================#
class Construction:
def __init__(self, name = "Default Opaque Construction", area = 1.0, normal = Vector3d(0, -1, 0), height = 1.0, thickness = 0.0, density = 1.5, U = 4.0):
self.name = name
self.materials = []
self.normal = normal
self.area = area
self.height = height
self.thickness = thickness
self.density = density
self.U = U
self.U_multiplier = 1.0
self.hour = 0
#GLOBAL OVERRIDES INITIALIZATION FOR INTERNAL TESTS ONLY
self.heat_capacity = 600 / 3600
self.absorbance = 0.3
self.reflectivity = 0.7
self.transmittance = 0.0
def AddLayer(self, material: OpaqueConstructionMaterial):
self.materials.append(material)
self.thickness += material.thickness
# TODO
# MASS
def SetTestValues(self, U, A, R, T):
self.U = U
self.absorbance = A
self.reflectivity = R
self.transmittance = T
def GetHeatlossCoeff(self):
return self.area * self.U_value
def GetUValue(self):
return self.U_value
def GetReflectivity(self, incident_angle):
# TEST
# TODO
return self.reflectivity
def GetTransmittance(self, incident_angle):
# TEST
# TODO
return self.transmittance
def GetAbsorbance(self, incident_angle):
# TEST
# TODO
return self.absorbance
def GetAverageReflectivity(self):
# TODO
return self.reflectivity
def GetAverageAbsorbance(self):
# TODO
return self.absorbance
def GetAverageTransmittance(self):
# TODO
return self.transmittance
@property
def Mass(self):
return self.thickness * self.area * self.density
@property
def HeatExchangeCoeff(self):
return self.U_value * self.area
@property
def HeatCapacity(self):
return self.heat_capacity
@property
def U_value(self):
return self.U * self.U_multiplier
#====================================#
class ProceduralRadiance:
def __init__(self, G_dir, G_diff, refl, altitude, azimuth, normal: Vector3d):
self.G_dir = G_dir
self.G_diff = G_diff
self.refl = refl
self.altitude = math.radians(altitude)
self.azimuth = math.radians(azimuth)
self.normal = normal
self.sun_vector = self.GetSunVector()
def Run(self):
self.alpha = self.GetAlpha()
self.dir_factor = self.GetDirFactor()
self.g_dir = self.GetDir()
self.beta = self.GetBeta()
self.gamma = self.GetGamma()
self.diff_factor = self.GetDiffFactor()
self.refl_factor = self.GetReflFactor()
self.g_diff = self.GetDiff()
self.g_refl = self.GetRefl()
self.g = self.GetG()
def GetSunVector(self):
if self.altitude == 0:
return Vector3d(0, -1, 0)
else:
x = math.cos(self.altitude) * math.sin(self.azimuth)
y = math.cos(self.altitude) * math.cos(self.azimuth)
z = math.sin(self.altitude)
return Vector3d(x, y, z)
def GetAlpha(self):
return abs(self.sun_vector.VectorAngle(self.normal, self.sun_vector))
def GetDirFactor(self):
if self.altitude == 0:
return 0
else:
if math.cos(self.alpha) <= 0:
return 0
else:
return math.cos(self.alpha)
def GetDir(self):
return self.G_dir * self.dir_factor
def GetBeta(self):
return math.sin(self.altitude)
def GetGamma(self):
return abs(self.normal.VectorAngle(self.normal, Vector3d(0, 0, 1)))
def GetDiffFactor(self):
return (1 + math.cos(self.gamma)) / 2
def GetReflFactor(self):
return (1 - math.cos(self.gamma)) / 2
def GetDiff(self):
return self.G_diff * self.diff_factor
def GetRefl(self):
return self.refl_factor * self.refl * (self.G_diff + self.G_dir * math.sin(self.beta))
def GetG(self):
return self.g_refl + self.g_diff + self.g_dir
def GetAnisotropicRadiation(self):
return self.g_dir
def GetIsotropicRadiation(self):
return self.g_diff + self.g_refl
class Fresnel:
def __init__(
self, refraction_index_1=1.0003,
refraction_index_2=1.52,
incident_angle=1 / 6 * math.pi,
s_polarized_ratio=0.5,
incident_energy=1,
backward_emission_energy=0.2,
material_1_name="Generic Air",
material_2_name="Generic Glass",
):
self.refraction_index_1 = refraction_index_1
self.refraction_index_2 = refraction_index_2
self.incident_angle = incident_angle
self.s_polarized_ratio = s_polarized_ratio
self.p_polarized_ratio = 1 - s_polarized_ratio
self.I = incident_energy
self.E = backward_emission_energy
self.material_1_name = material_1_name
self.material_2_name = material_2_name
self.graph_lines = []
self.length = 2
self.refl()
self.energy()
def refl(self):
ct = math.cos(self.incident_angle)
n1 = self.refraction_index_1
n2 = self.refraction_index_2
p2 = math.sqrt(abs(1 - (n1 / n2 * math.sin(self.incident_angle)) ** 2))
rs = ((n1 * ct - n2 * p2) / (n1 * ct + n2 * p2)) ** 2
rp = ((n1 * p2 - n2 * ct) / (n1 * p2 + n2 * ct)) ** 2
self.reflectivity = self.s_polarized_ratio * rs + self.p_polarized_ratio * rp
self.refl_s = rs
self.refl_p = rp
self.transmit_angle = abs(math.asin(n1 / n2 * math.sin(self.incident_angle)))
ctb = math.cos(self.transmit_angle)
p2b = math.sqrt(abs(1 - (n2 / n1 * math.sin(self.transmit_angle)) ** 2))
rsb = ((n2 * ctb - n1 * p2b) / (n2 * ctb + n1 * p2b)) ** 2
rpb = ((n2 * p2b - n1 * ctb) / (n2 * p2b + n1 * ctb)) ** 2
self.backward_reflectivity = self.s_polarized_ratio * rsb + self.p_polarized_ratio * rpb
self.back_refl_s = rsb
self.back_refl_p = rpb
return
def energy(self):
self.TI = self.I * (1 - self.reflectivity)
self.TE = self.E * self.backward_reflectivity
self.RI = self.I * self.reflectivity
self.RE = self.E * (1 - self.backward_reflectivity)
self.T = self.TI + self.TE
self.R = self.RI + self.RE
return
class Weather:
# An Hourly Record from the Observed Climatic Records
def __init__(self, index, temperature, azimuth, altitude, direct_radiation, diffuse_radiation, wind_speed, wind_direction, pressure):
self.index = index
self.temperature = temperature
self.azimuth = azimuth
self.altitude = altitude
self.direct_radiation = direct_radiation
self.diffuse_radiation = diffuse_radiation
self.wind_speed = wind_speed
self.wind_direction = wind_direction
self.pressure = pressure
def GetProceduralRadianceObject(self):
return ProceduralRadiance(self.direct_radiation, self.diffuse_radiation, 0.3, self.altitude, self.azimuth, Vector3d(0, -1, 0))
def GetExteriorAirHeatCapacity(self):
return 1005.0 / 3600
def GetAirDensity(self):
# EXPERIMENTAL ESTIMATIONS
return 1.225
class WeatherSet:
def __init__(self):
self.records = []
def AddRecord(self, weather: Weather):
self.records.append(weather)
def GetRecord(self, index) -> Weather:
return self.records[index]
@property
def Length(self):
return len(self.records)
def IsSummerTime(self, hour):
if hour <= 6500 and hour >= 3600:
return True
else:
return False
def IsDayTime(self, hour):
hod = hour - 24 * (math.floor(hour / 24))
if hod >= 6 and hod <= 18:
return True
else:
return False
class Strategy:
def __init__(self, hour: int=0, opening_ratio=1.0, interior_opening_ratio=0.02, shading_ratio=0.05, north_opening_ratio = 0.05, heating_threshold = 10.0, heating_goal = 15.0, cooling_goal = 25.0, cooling_threshold = 32.0, internal_gain = 1.2):
self.hour = hour
self.opening_ratio = opening_ratio
self.interior_opening_ratio = interior_opening_ratio
self.north_opening_ratio = north_opening_ratio
self.shading_ratio = shading_ratio
self.heating_threshold = heating_threshold
self.heating_goal = heating_goal
self.cooling_threshold = cooling_threshold
self.cooling_goal = cooling_goal
self.internal_gain = internal_gain
self.nightpurge_start = 3600
self.nightpurge_end = 7000
self.summer_window_u_value_multiplier = 1.0
self.summer_night_purge = False
self.summer_shading = False
self.summer_ventilation = False
self.enclose_wintergarden = False
@property
def IsDayTime(self):
ws = WeatherSet()
return ws.IsDayTime(self.hour)
@property
def IsSummerTime(self):
ws = WeatherSet()
return ws.IsSummerTime(self.hour)
def __str__(self):
# TODO: describe different strategies in strings
pass
def DoSummerNightPurge(self, purge: bool):
self.summer_night_purge = purge
def SetSummerWindowUValueMultiplier(self, param):
self.summer_window_u_value_multiplier = param
def DoSummerShading(self, shade: bool):
self.summer_shading = shade
def DoSummerVentilation(self, vent: bool):
self.summer_ventilation = vent
def DoEncloseWintergarden(self, enclose: bool):
self.enclose_wintergarden = enclose
@property
def UMultipier(self):
if self.IsSummerTime:
return self.summer_window_u_value_multiplier
else:
return 1.0
@property
def MaximumVentilation(self):
if self.summer_ventilation and self.IsSummerTime:
return True
"""
if self.summer_night_purge and self.IsSummerTime:
if self.IsDayTime:
return False
else:
return True
"""
return False
@property
def Shading(self):
if self.IsSummerTime and self.summer_shading:
return 1.0
else:
return self.shading_ratio
class StrategySet:
def __init__(self):
self.strategies = []
def AddStrategy(self, strategy: Strategy):
self.strategies.append(strategy)
def GetStrategy(self, index) -> Strategy:
return self.strategies[index]
def SetStrategy(self, strategy: Strategy, index):
self.strategies[index] = strategy
# TODO add other useful methods to create strategy sets differently
class Exterior:
def __init__(self, weather: Weather, constructions: List[Construction]):
self.weather = weather
self.constructions = constructions
self.area = 0
for construction in self.constructions:
self.area += construction.area
@property
def HeatExchangeCoeff(self):
coeff = 0.0
for construction in self.constructions:
coeff += construction.HeatExchangeCoeff
return coeff
class Wintergarden:
def __init__(self, weather: Weather, constructions: List[Construction], maximum_opening, offset):
self.weather = weather
self.maximum_opening = maximum_opening
self.offset = offset
self.opening_ratio = 0.2
self.shading_ratio = 0.0
self.opening = self.opening_ratio * self.maximum_opening
self.constructions = constructions
self.height = 8.0
self.pending_heat = 0.0
self.temperature = 12
self.exterior_ventilation_rate = 0.0
self.exterior_infiltration_rate = 0.0
self.interior_ventilation_rate = 0.0
self.interior_infiltration_rate = 0.0
def ApplyStrategy(self, strategy: Strategy):
self.opening_ratio = strategy.opening_ratio
if strategy.MaximumVentilation:
self.opening_ratio = 1.0
else:
self.opening_ratio = 0.05
self.opening = self.opening_ratio * self.maximum_opening
self.shading_ratio = strategy.Shading
for construction in self.constructions:
if construction.GetAverageTransmittance() >= 0.1:
construction.U_multiplier = strategy.UMultipier
# TEST
if strategy.enclose_wintergarden:
pass
else:
self.temperature = self.weather.temperature
def SetFloorConstruction(self, construction: Construction):
self.floor_construction = construction
def SetShadingConstruction(self, construction: Construction):
self.shading_construction = construction
@property
def FaceArea(self):
a = 0.0
for construction in self.constructions:
a += construction.area
return a
@property
def Mass(self):
mass = 0
for construction in self.constructions:
mass += construction.Mass
mass += self.floor_construction.Mass
return mass
@property
def HeatExchangeCoeff(self):
coeff = 0.0
for construction in self.constructions:
coeff += construction.HeatExchangeCoeff
return coeff
@property
def TotalHeatCapacity(self):
hc = 0.0
for construction in self.constructions:
hc += construction.Mass * construction.HeatCapacity
hc += self.shading_construction.Mass * self.shading_construction.heat_capacity
hc += self.FaceArea * self.offset * self.weather.GetAirDensity() * self.weather.GetExteriorAirHeatCapacity()
return hc
@property
def StackEffectPressureDifference(self):
return abs(0.0342 * self.weather.pressure * self.height * (1 / (self.temperature + 273) - 1 / (self.weather.temperature + 273)))
def StackEffectFlowRate(self, temperature):
return 0.65 * self.opening * math.sqrt(abs(2 * 9.807 * self.height / 2 * (self.temperature - temperature) / (self.temperature + 273))) * 3600
def GetVentilationHeatExchange(self, temperature, flow):
total_heat = self.TotalHeatCapacity * (self.temperature - temperature)
volume_heat = self.TotalHeatCapacity / (self.TotalHeatCapacity + self.weather.GetAirDensity() * self.weather.GetExteriorAirHeatCapacity() * flow) * total_heat
return volume_heat - total_heat
class Interior:
def __init__(self, weather: Weather, constructions: List[Construction], maximum_opening, offset):
self.weather = weather
self.shading_ratio = 0.05
self.opening_ratio = 0.0
self.constructions = constructions
self.height = 6.5
self.offset = offset
self.maximum_opening = maximum_opening
self.opening = self.maximum_opening * self.opening_ratio
self.pending_heat = 0.0
self.temperature = 12.0
self.exterior_ventilation_rate = 0.0
self.exterior_infiltration_rate = 0.0
self.room_ventilation_rate = 2000
self.room_infiltration_rate = 50
self.heating_threshold = 10.0
self.heating_goal = 20
self.cooling_threshold = 35.0
self.cooling_goal = 26.0
self.internal_gain = 0.0
def ApplyStrategy(self, strategy: Strategy):
self.opening_ratio = strategy.interior_opening_ratio
if strategy.MaximumVentilation:
self.opening_ratio = 1.0
else:
self.opening_ratio = 0.05
self.opening = self.opening_ratio * self.maximum_opening
self.internal_gain = strategy.internal_gain * self.floor_construction.area
self.heating_threshold = strategy.heating_threshold
self.heating_goal = strategy.heating_goal
self.cooling_threshold = strategy.cooling_threshold
self.cooling_goal = strategy.cooling_goal
for construction in self.constructions:
if construction.GetAverageTransmittance() >= 0.1:
construction.U_multiplier = strategy.UMultipier
def SetFloorConstruction(self, construction: Construction):
self.floor_construction = construction
def SetPartyWallConstruction(self, construction: Construction):
self.party_wall_construction = construction
@property
def FaceArea(self):
a = 0.0
for construction in self.constructions:
a += construction.area
return a
@property
def Mass(self):
mass = 0.0
for construction in self.constructions:
mass += construction.Mass
mass += self.floor_construction.Mass
mass += self.party_wall_construction.Mass
return mass
@property
def HeatExchangeCoeff(self):
coeff = 0.0
for construction in self.constructions:
coeff += construction.HeatExchangeCoeff
return coeff
@property
def TotalHeatCapacity(self):
hc = 0.0
for construction in self.constructions:
hc += construction.Mass * construction.HeatCapacity
hc += self.floor_construction.Mass * self.floor_construction.heat_capacity
hc += self.party_wall_construction.Mass * self.party_wall_construction.heat_capacity
hc += self.FaceArea * self.height * self.weather.GetAirDensity() * self.weather.GetExteriorAirHeatCapacity()
return hc
@property
def StackEffectPressureDifference(self):
return abs(0.0342 * self.weather.pressure * self.height * (1 / (self.temperature + 273) - 1 / (self.weather.temperature + 273)))
def StackEffectFlowRate(self, temperature):
return 0.65 * self.opening * math.sqrt(abs(2 * 9.807 * self.height / 2 * (self.temperature - temperature) / (self.temperature + 273))) * 3600
def GetVentilationHeatExchange(self, temperature, flow):
total_heat = self.TotalHeatCapacity * (self.temperature - temperature)
volume_heat = self.TotalHeatCapacity / (self.TotalHeatCapacity + self.weather.GetAirDensity() * self.weather.GetExteriorAirHeatCapacity() * flow) * total_heat
return volume_heat - total_heat
class Room:
def __init__(self, weather: Weather, constructions: List[Construction], opening_ratio=0.0):
self.weather = weather
self.constructions = constructions
self.opening_ratio = opening_ratio
self.maximum_opening = 6.2
self.opening = opening_ratio * self.maximum_opening
self.height = 3.8
self.offset = 4.4
self.pending_heat = 0.0
self.temperature = 15.0
self.exterior_ventilation_rate = 0.0
self.exterior_infiltration_rate = 0.0
self.interior_ventilation_rate = 2000
self.interior_infiltration_rate = 50
self.heating_threshold = 10.0
self.heating_goal = 20
self.cooling_threshold = 35.0
self.cooling_goal = 26.0
self.internal_gain = 0.0
def ApplyStrategy(self, strategy: Strategy):
self.internal_gain = strategy.internal_gain * self.floor_construction.area
self.opening_ratio = strategy.north_opening_ratio
if strategy.MaximumVentilation:
self.opening_ratio = 1.0
else:
self.opening_ratio = 0
self.opening = self.opening_ratio * self.maximum_opening
self.heating_threshold = strategy.heating_threshold
self.heating_goal = strategy.heating_goal
self.cooling_threshold = strategy.cooling_threshold
self.cooling_goal = strategy.cooling_goal
self.opening_ratio = strategy.north_opening_ratio
self.opening = self.opening_ratio * self.maximum_opening
for construction in self.constructions:
if construction.GetAverageTransmittance() >= 0.1:
construction.U_multiplier = strategy.UMultipier
def SetFloorConstruction(self, construction: Construction):
self.floor_construction = construction
def SetPartyWallConstruction(self, construction: Construction):
self.party_wall_construction = construction
@property
def FaceArea(self):
a = 0.0
for construction in self.constructions:
a += construction.area
return a
@property
def Mass(self):
mass = 0.0
for construction in self.constructions:
mass += construction.Mass
mass += self.floor_construction.Mass
mass += self.party_wall_construction.Mass
return mass
@property
def HeatExchangeCoeff(self):
coeff = 0.0
for construction in self.constructions:
coeff += construction.HeatExchangeCoeff
return coeff
@property
def TotalHeatCapacity(self):
hc = 0.0
for construction in self.constructions:
hc += construction.Mass * construction.HeatCapacity
hc += self.floor_construction.Mass * self.floor_construction.heat_capacity
hc += self.party_wall_construction.Mass * self.party_wall_construction.heat_capacity
hc += self.FaceArea * self.height * self.weather.GetAirDensity() * self.weather.GetExteriorAirHeatCapacity()
return hc
@property
def StackEffectPressureDifference(self):
return abs(0.0342 * self.weather.pressure * self.height * (1 / (self.temperature + 273) - 1 / (self.weather.temperature + 273)))
def StackEffectFlowRate(self, temperature):
return 0.65 * self.opening * math.sqrt(abs(2 * 9.807 * self.height / 2 * (self.temperature - temperature) / (self.temperature + 273))) * 3600
def GetVentilationHeatExchange(self, temperature, flow):
total_heat = self.TotalHeatCapacity * (self.temperature - temperature)
volume_heat = self.TotalHeatCapacity / (self.TotalHeatCapacity + self.weather.GetAirDensity() * self.weather.GetExteriorAirHeatCapacity() * flow) * total_heat
return volume_heat - total_heat
class Model:
def __init__(self, exterior: Exterior, wintergarden: Wintergarden, interior: Interior, room: Room, weatherset: WeatherSet, strategyset: StrategySet, starting_hour = 0, analysis_period = -1):
self.exterior = exterior
self.wintergarden = wintergarden
self.interior = interior
self.room = room
self.weatherset = weatherset
self.weather = weatherset.GetRecord(0)
self.strategyset = strategyset
self.strategy = strategyset.GetStrategy(0)
self.hour = starting_hour
self.analysis_period = analysis_period
self.ready = True
self.results = SimulationResults()
def UpdateModel(self):
self.UpdateStrategy()
self.UpdateWeather()
self.UpdateSolarGain()
self.UpdateVentilationLoss()
self.UpdateLatentHeat()
self.UpdateInternalGain()
self.UpdateHeatTransfer()
self.UpdateVentilationRate()
self.UpdateResult()
if self.interior.temperature <= 200:
print(str(self.hour) + " " +str(self.exterior.weather.temperature) + " " + str(self.wintergarden.temperature) + " " +str(self.interior.temperature) + " " +str(self.room.temperature))
if self.hour >= self.weatherset.Length - 1:
self.ready = False
return False
if self.analysis_period != 0:
self.analysis_period += -1
self.hour += 1
self.ready = True
return True
else:
self.ready = False
return False
def UpdateStrategy(self):
self.strategy = self.strategyset.GetStrategy(0)#self.hour#)
self.strategy.hour = self.hour
self.wintergarden.ApplyStrategy(self.strategy)
self.interior.ApplyStrategy(self.strategy)
self.room.ApplyStrategy(self.strategy)
def UpdateWeather(self):
self.weather = self.weatherset.GetRecord(self.hour)
self.exterior.weather = self.weather
self.wintergarden.weather = self.weather
self.interior.weather = self.weather
self.procedural_radiance_object = self.weather.GetProceduralRadianceObject()
def UpdateSolarGain(self):
wintergarden_absorbed_radiation = 0.0
inner_screen_anisotropic_radiation = 0.0
inner_screen_isotropic_radiation = 0.0
interior_absorbed_radiation = 0.0
room_absorbed_radiation = 0.0
# simulation result energy breakdowns
wintergarden_radiation_from_anisotropic = 0.0
wintergarden_radiation_from_isotropic = 0.0
interior_radiation_from_anisotropic = 0.0
interior_radiation_from_isotropic_south = 0.0
interior_radiation_from_isotropic_north = 0.0
for construction in self.exterior.constructions: # first screen layer
self.procedural_radiance_object.normal = construction.normal
self.procedural_radiance_object.Run()
ani_rad = self.procedural_radiance_object.GetAnisotropicRadiation() * construction.area
iso_rad = self.procedural_radiance_object.GetIsotropicRadiation() * construction.area
if ani_rad > 0:
# anisotropic radiation transmitted into the wintergarden
ani_rad = construction.GetTransmittance(self.procedural_radiance_object.alpha) * ani_rad
# anisotropic radiation absorbed in the fenestrations on the screen
wintergarden_absorbed_radiation += construction.GetAbsorbance(self.procedural_radiance_object.alpha) * ani_rad
# update to simulation result energy breakdowns
wintergarden_radiation_from_anisotropic += construction.GetAbsorbance(self.procedural_radiance_object.alpha) * ani_rad
else:
ani_rad = 0
# isotropic radiation transmitted into the wintergarden
iso_rad = construction.GetAverageTransmittance() * iso_rad
# isotropic radiation absorbed in the fenestrations on the screen
wintergarden_absorbed_radiation += construction.GetAverageAbsorbance() * iso_rad
# update to simulation result energy breakdowns
wintergarden_radiation_from_isotropic += construction.GetAverageAbsorbance() * iso_rad
# angle of the global ZAxis and the fenestration normal
angle = construction.normal.VectorAngle(construction.normal, Vector3d(0, 0, 1))
if angle >= math.pi / 2:
angle = math.pi - angle
# ratio of the radiation from fenestrations hitting firstly the wintergarden floor
wintergarden_floor_viewfactor = self.wintergarden.offset * math.cos(angle) / construction.height
if wintergarden_floor_viewfactor > 1:
wintergarden_floor_viewfactor = 1
# anisotropic radiation absorbed by the wintergarden floor
wintergarden_absorbed_radiation += self.wintergarden.floor_construction.GetAbsorbance(math.pi / 2 - self.procedural_radiance_object.altitude) * ani_rad * wintergarden_floor_viewfactor
# update to simulation result energy breakdowns
wintergarden_radiation_from_anisotropic += self.wintergarden.floor_construction.GetAbsorbance(math.pi / 2 - self.procedural_radiance_object.altitude) * ani_rad * wintergarden_floor_viewfactor
# anisotropic radiation incident onto inner envelope
ani_rad = (1 - wintergarden_floor_viewfactor) * ani_rad
# isotropic radiation absorbed by the wintergarden floor
wintergarden_absorbed_radiation += self.wintergarden.floor_construction.GetAverageAbsorbance() * iso_rad * wintergarden_floor_viewfactor
# update to simulation result energy breakdowns
wintergarden_radiation_from_isotropic += self.wintergarden.floor_construction.GetAverageAbsorbance() * iso_rad * wintergarden_floor_viewfactor
# isotropic radiation reflected by the wintergarden floor, half of which contributes to isotropic radiation incident onto inner envelope
iso_rad_bypass = iso_rad * (1 - wintergarden_floor_viewfactor)
iso_rad = self.wintergarden.floor_construction.GetAverageReflectivity() * iso_rad / 2 * wintergarden_floor_viewfactor
# anisotropic radiation reflected by the wintergarden floor, half of which contributes to isotropic radiation incident onto inner envelope
iso_rad += self.wintergarden.floor_construction.GetReflectivity(math.pi / 2 - self.procedural_radiance_object.altitude) * ani_rad / 2 * wintergarden_floor_viewfactor
# isotropic radiation directly incident on inner envelope
iso_rad += iso_rad_bypass
inner_screen_isotropic_radiation += iso_rad
inner_screen_anisotropic_radiation += ani_rad
# shading
self.procedural_radiance_object.normal = self.wintergarden.shading_construction.normal
self.procedural_radiance_object.Run()
portion_shaded = self.wintergarden.shading_construction.area / self.wintergarden.FaceArea * self.wintergarden.shading_ratio
shading_radiation_from_isotropic = 0.0
shading_radiation_from_anisotropic = 0.0
shading_radiation_from_anisotropic += portion_shaded * inner_screen_anisotropic_radiation * self.wintergarden.shading_construction.GetReflectivity(self.procedural_radiance_object.alpha) * self.wintergarden.offset / math.pi / 2
shading_radiation_from_anisotropic += portion_shaded * inner_screen_anisotropic_radiation * self.wintergarden.shading_construction.GetAbsorbance(self.procedural_radiance_object.alpha) * self.wintergarden.offset / math.pi / 2
shading_radiation_from_isotropic += portion_shaded * inner_screen_isotropic_radiation * self.wintergarden.shading_construction.GetAverageAbsorbance()
shading_radiation_from_isotropic += portion_shaded * inner_screen_isotropic_radiation * self.wintergarden.shading_construction.GetAverageReflectivity() * self.wintergarden.offset / math.pi / 2
wintergarden_radiation_from_anisotropic += shading_radiation_from_anisotropic
wintergarden_radiation_from_isotropic += shading_radiation_from_isotropic
wintergarden_absorbed_radiation += shading_radiation_from_isotropic + shading_radiation_from_anisotropic
# 0304 ADDED
inner_screen_anisotropic_radiation += -shading_radiation_from_anisotropic
inner_screen_isotropic_radiation += -shading_radiation_from_isotropic
for construction in self.wintergarden.constructions: # second screen layer
self.procedural_radiance_object.normal = construction.normal
self.procedural_radiance_object.Run()
local_anisotropic_radiation = inner_screen_anisotropic_radiation * construction.area / self.wintergarden.FaceArea
local_isotropic_radiation = inner_screen_isotropic_radiation * construction.area / self.wintergarden.FaceArea
# interior radiation gain from transmitted anisotropic radiation
interior_absorbed_radiation += local_anisotropic_radiation * construction.GetTransmittance(self.procedural_radiance_object.alpha)
# update to simulation result energy breakdowns
interior_radiation_from_anisotropic += local_anisotropic_radiation * construction.GetTransmittance(self.procedural_radiance_object.alpha)
# interior radiation absorbed from fabric material absorbance, isotropic sector
interior_absorbed_radiation += local_isotropic_radiation * construction.GetAverageAbsorbance()
# update to simulation result energy breakdowns
interior_radiation_from_isotropic_south += local_isotropic_radiation * construction.GetAverageAbsorbance()
# interior radiation absorbed from fabric material absorbance, anisotropic sector
interior_absorbed_radiation += local_anisotropic_radiation * construction.GetAbsorbance(self.procedural_radiance_object.alpha)
# update to simulation result energy breakdowns
interior_radiation_from_anisotropic += local_anisotropic_radiation * construction.GetAbsorbance(self.procedural_radiance_object.alpha)
# wintergarden radiation gain from inner screen reflection, isotropic sector
wintergarden_absorbed_radiation += self.wintergarden.offset / math.pi / 2 * (local_isotropic_radiation * construction.GetAverageReflectivity())
# update to simulation result energy breakdowns
wintergarden_radiation_from_isotropic += self.wintergarden.offset / math.pi / 2 * (local_isotropic_radiation * construction.GetAverageReflectivity())
# wintergarden radiation gain from inner screen reflection, anisotropic sector
wintergarden_absorbed_radiation += self.wintergarden.offset / math.pi / 2 * (local_anisotropic_radiation * construction.GetReflectivity(self.procedural_radiance_object.alpha))
# update to simulation result energy breakdowns
wintergarden_radiation_from_anisotropic += self.wintergarden.offset / math.pi / 2 * (local_anisotropic_radiation * construction.GetReflectivity(self.procedural_radiance_object.alpha))
# interior radiation gain from transmitted isotropic radiation
interior_absorbed_radiation += local_isotropic_radiation * construction.GetAverageTransmittance()
# update to simulation result energy breakdowns
interior_radiation_from_isotropic_south += local_isotropic_radiation * construction.GetAverageTransmittance()
for construction in self.room.constructions: # north facing facade
self.procedural_radiance_object.normal = construction.normal
self.procedural_radiance_object.Run()
iso_rad = self.procedural_radiance_object.GetIsotropicRadiation() * construction.area
# isotropic radiation transmitted into the interior
room_absorbed_radiation += iso_rad * construction.GetAverageTransmittance()
# update to simulation result energy breakdowns
interior_radiation_from_isotropic_north += iso_rad * construction.GetAverageTransmittance()
# isotropic radiation absorbed by the fabric
room_absorbed_radiation += iso_rad * construction.GetAverageAbsorbance()
# update to simulation result energy breakdowns
interior_radiation_from_isotropic_north += iso_rad * construction.GetAverageAbsorbance()
self.wintergarden.pending_heat += wintergarden_absorbed_radiation
self.interior.pending_heat += interior_absorbed_radiation
self.room.pending_heat += room_absorbed_radiation
self.results.wintergarden_radiation_from_anisotropic.append(wintergarden_radiation_from_anisotropic)
self.results.wintergarden_radiation_from_isotropic.append(wintergarden_radiation_from_isotropic)
self.results.interior_radiation_from_isotropic_north.append(interior_radiation_from_isotropic_north)
self.results.interior_radiation_from_isotropic_south.append(interior_radiation_from_isotropic_south)
self.results.interior_radiation_from_anisotropic.append(interior_radiation_from_anisotropic)
self.results.shading_radiation_from_anisotropic.append(shading_radiation_from_anisotropic)
self.results.shading_radiation_from_isotropic.append(shading_radiation_from_isotropic)
# TEST
# print(wintergarden_absorbed_radiation)
# print(interior_absorbed_radiation)
def UpdateVentilationLoss(self):
if self.hour >= 3598:
pass
# TODO REWORK ON THIS?
self.wintergarden.exterior_ventilation_rate = self.wintergarden.StackEffectFlowRate(self.weather.temperature)
self.wintergarden.interior_ventilation_rate = self.interior.StackEffectFlowRate(self.wintergarden.temperature)
self.wintergarden.exterior_infiltration_rate = (self.weather.wind_speed * 0.02 + 0.02) * 3600
self.wintergarden.interior_infiltration_rate = (self.weather.wind_speed * 0.01 + 0.01) * 3600
self.interior.wintergarden_infiltration_rate = 0.02 * 3600
self.wintergarden.interior_infiltration_rate = 0.02 * 3600
self.room.exterior_ventilation_rate = (self.weather.wind_speed * 0.02 + 0.02) * 3600
self.room.exterior_infiltration_rate = (self.weather.wind_speed * 0.01 + 0.01) * 3600