-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosut.py
More file actions
8809 lines (7019 loc) · 296 KB
/
Copy pathosut.py
File metadata and controls
8809 lines (7019 loc) · 296 KB
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
# BSD 3-Clause License
#
# Copyright (c) 2022-2025, rd2
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import re
import math
import collections
import openstudio
from oslg import oslg
from dataclasses import dataclass
@dataclass(frozen=True)
class _CN:
DBG = oslg.CN.DEBUG
INF = oslg.CN.INFO
WRN = oslg.CN.WARN
ERR = oslg.CN.ERROR
FTL = oslg.CN.FATAL
TOL = 0.01 # default distance tolerance (m)
TOL2 = TOL * TOL # default area tolerance (m2)
HEAD = 2.032 # standard 80" door
SILL = 0.762 # standard 30" window sill
CN = _CN()
# General surface orientations (see 'facets' method).
_sidz = ("bottom", "top", "north", "east", "south", "west")
# This first set of utilities support OpenStudio materials, constructions,
# construction sets, etc. If relying on default StandardOpaqueMaterial:
# - roughness (rgh) : "Smooth"
# - thickness : 0.1 m
# - thermal conductivity (k ) : 0.1 W/m.K
# - density (rho) : 0.1 kg/m3
# - specific heat (cp ) : 1400.0 J/kg•K
#
# https://s3.amazonaws.com/openstudio-sdk-documentation/cpp/
# OpenStudio-3.6.1-doc/model/html/
# classopenstudio_1_1model_1_1_standard_opaque_material.html
# ... apart from surface roughness, rarely would these material properties be
# suitable - and are therefore explicitly set below. On roughness:
# - "Very Rough" : stucco
# - "Rough" : brick
# - "Medium Rough" : concrete
# - "Medium Smooth" : clear pine
# - "Smooth" : smooth plaster
# - "Very Smooth" : glass
# Thermal mass categories (e.g. exterior cladding, interior finish, framing).
# - "none" : token for 'no user selection', resort to defaults
# - "light" : e.g. 16mm drywall interior
# - "medium" : e.g. 100mm brick cladding
# - "heavy" : e.g. 200mm poured concrete
_mass = ("none", "light", "medium", "heavy")
# Basic materials (StandardOpaqueMaterials only).
_mats = dict(
material = {}, # generic, e.g. lightweight cladding over furring, fibreboard
sand = {},
concrete = {},
brick = {},
drywall = {}, # e.g. finished drywall, intermediate sheating
mineral = {}, # e.g. light, semi-rigid rock wool insulation
polyiso = {}, # e.g. polyisocyanurate panel (or similar)
cellulose = {}, # e.g. blown, dry/stabilized fibre
door = {} # single composite material (45mm insulated steel door)
)
# Default inside + outside air film resistances (m2.K/W).
_film = dict(
shading = 0.000, # NA
partition = 0.150, # uninsulated wood- or steel-framed wall
wall = 0.150, # un/insulated wall
roof = 0.140, # un/insulated roof
floor = 0.190, # un/insulated (exposed) floor
basement = 0.120, # un/insulated basement wall
slab = 0.160, # un/insulated basement slab or slab-on-grade
door = 0.150, # standard, 45mm insulated steel (opaque) door
window = 0.150, # vertical fenestration, e.g. glazed doors, windows
skylight = 0.140 # e.g. domed 4' x 4' skylight
)
# Default (~1980s) envelope Uo (W/m2•K), based on surface type.
_uo = dict(
shading = None, # N/A
partition = None, # N/A
wall = 0.384, # rated R14.8 hr•ft2F/Btu
roof = 0.327, # rated R17.6 hr•ft2F/Btu
floor = 0.317, # rated R17.9 hr•ft2F/Btu (exposed floor)
basement = None,
slab = None,
door = 1.800, # insulated, unglazed steel door (single layer)
window = 2.800, # e.g. patio doors (simple glazing)
skylight = 3.500 # all skylight technologies
)
# Standard opaque materials, taken from a variety of sources (e.g. energy
# codes, NREL's BCL).
# - sand
# - concrete
# - brick
#
# Material properties remain largely constant between projects. What does
# tend to vary (between projects) are thicknesses. Actual OpenStudio opaque
# material objects can be (re)set in more than one way by class methods.
# In genConstruction, OpenStudio object identifiers are later suffixed with
# actual material thicknesses, in mm, e.g.:
# - "concrete200" : 200mm concrete slab
# - "drywall13" : 1/2" gypsum board
# - "drywall16" : 5/8" gypsum board
#
# Surface absorptances are also defaulted in OpenStudio:
# - thermal, long-wave (thm) : 90%
# - solar (sol) : 70%
# - visible (vis) : 70%
#
# These can also be explicitly set (see "sand").
_mats["material" ]["rgh"] = "MediumSmooth"
_mats["material" ]["k" ] = 0.115
_mats["material" ]["rho"] = 540.000
_mats["material" ]["cp" ] = 1200.000
_mats["sand" ]["rgh"] = "Rough"
_mats["sand" ]["k" ] = 1.290
_mats["sand" ]["rho"] = 2240.000
_mats["sand" ]["cp" ] = 830.000
_mats["sand" ]["thm"] = 0.900
_mats["sand" ]["sol"] = 0.700
_mats["sand" ]["vis"] = 0.700
_mats["concrete" ]["rgh"] = "MediumRough"
_mats["concrete" ]["k" ] = 1.730
_mats["concrete" ]["rho"] = 2240.000
_mats["concrete" ]["cp" ] = 830.000
_mats["brick" ]["rgh"] = "Rough"
_mats["brick" ]["k" ] = 0.675
_mats["brick" ]["rho"] = 1600.000
_mats["brick" ]["cp" ] = 790.000
_mats["drywall" ]["k" ] = 0.160
_mats["drywall" ]["rho"] = 785.000
_mats["drywall" ]["cp" ] = 1090.000
_mats["mineral" ]["k" ] = 0.050
_mats["mineral" ]["rho"] = 19.000
_mats["mineral" ]["cp" ] = 960.000
_mats["polyiso" ]["k" ] = 0.025
_mats["polyiso" ]["rho"] = 25.000
_mats["polyiso" ]["cp" ] = 1590.000
_mats["cellulose"]["rgh"] = "VeryRough"
_mats["cellulose"]["k" ] = 0.050
_mats["cellulose"]["rho"] = 80.000
_mats["cellulose"]["cp" ] = 835.000
_mats["door" ]["rgh"] = "MediumSmooth"
_mats["door" ]["k" ] = 0.080
_mats["door" ]["rho"] = 600.000
_mats["door" ]["cp" ] = 1000.000
def sidz() -> tuple:
"""Returns available 'sidz' keywords."""
return _sidz
def mass() -> tuple:
"""Returns available 'mass' keywords."""
return _mass
def mats() -> dict:
"""Returns stored materials dictionary."""
return _mats
def film() -> dict:
"""Returns inside + outside air film resistance dictionary."""
return _film
def uo() -> dict:
"""Returns (surface type-specific) Uo dictionary."""
return _uo
def each_cons(it, n):
"""A proxy for Ruby enumerate's 'each_cons(n)' method.
Args:
it:
A sequence.
n (int):
The number of sequential items in sequence.
Returns:
tuple: n-sized sequenced items.
"""
# see: docs.ruby-lang.org/en/3.2/enumerate.html#method-i-each_cons
#
# James Wong's Python workaround implementation:
# stackoverflow.com/questions/5878403/python-equivalent-to-rubys-each-cons
# Convert as iterator.
it = iter(it)
deq = collections.deque()
# Insert first n items to a list first.
for _ in range(n):
try:
deq.append(next(it))
except StopIteration:
for _ in range(n - len(deq)):
deq.append(None)
yield tuple(deq)
return
yield tuple(deq)
# Main loop.
while True:
try:
val = next(it)
except StopIteration:
return
deq.popleft()
deq.append(val)
yield tuple(deq)
def clamp(value, minimum, maximum) -> float:
"""In-house alternative to Numpy's 'clip' (re: Ruby's 'clamp').
Args:
value (float):
A float-convertible value (to clip/clamp).
minimum (float):
Lower bound.
maximum (float):
Upper bound.
Returns:
float: Clamped value. Either value, min, max or '0' if invalid inputs.
"""
try:
value = float(value)
except:
try:
minimum = float(minimum)
return minimum
except:
try:
maximum = float(maximum)
return maximum
except:
return 0.0
try:
minimum = float(minimum)
except:
return value
try:
maximum = float(maximum)
except:
return value
if value < minimum: return minimum
if value > maximum: return maximum
return value
def genConstruction(model=None, specs=dict()):
"""Generates an OpenStudio multilayered construction, + materials if needed.
Args:
specs:
A dictionary holding multilayered construction parameters:
- "id" (str): construction identifier
- "type" (str): surface type - see OSut 'uo()'
- "uo" (float): assembly clear-field Uo, in W/m2•K - see OSut 'uo()'
- "clad" (str): exterior cladding - see OSut 'mass()'
- "frame" (str): assembly framing - see OSut 'mass()'
- "finish" (str): interior finish - see OSut 'mass()'
Returns:
openstudio.model.Construction: A generated construction.
None: If invalid inputs (see logs).
"""
mth = "osut.genConstruction"
cl = openstudio.model.Model
if not isinstance(model, cl):
return oslg.mismatch("model", model, cl, mth, CN.DBG)
if not isinstance(specs, dict):
return oslg.mismatch("specs", specs, dict, mth, CN.DBG)
if "type" not in specs: specs["type"] = "wall"
if "id" not in specs: specs["id" ] = ""
ide = oslg.trim(specs["id"])
if not ide:
ide = "OSut.CON." + specs["type"]
if specs["type"] not in uo():
return oslg.invalid("surface type", mth, 2, CN.ERR)
if "uo" not in specs: specs["uo"] = uo()[ specs["type"] ] # can be None
u = specs["uo"]
if u:
try:
u = float(u)
except:
return oslg.mismatch(id + " Uo", u, float, mth, CN.ERR)
if u < 0:
return oslg.negative(id + " Uo", mth, CN.ERR)
if round(u, 2) == 0:
return oslg.zero(id + " Uo", mth, CN.ERR)
if u > 5.678:
return oslg.invalid(id + " Uo (> 5.678)", mth, 2, CN.ERR)
# Optional specs. Log/reset if invalid.
if "clad" not in specs: specs["clad" ] = "light" # exterior
if "frame" not in specs: specs["frame" ] = "light"
if "finish" not in specs: specs["finish"] = "light" # interior
if specs["clad" ] not in mass(): oslg.log(CN.WRN, "Reset: light cladding")
if specs["frame" ] not in mass(): oslg.log(CN.WRN, "Reset: light framing")
if specs["finish"] not in mass(): oslg.log(CN.WRN, "Reset: light finish")
if specs["clad" ] not in mass(): specs["clad" ] = "light"
if specs["frame" ] not in mass(): specs["frame" ] = "light"
if specs["frame" ] not in mass(): specs["finish"] = "light"
flm = film()[ specs["type"] ]
# Layered assembly (max 4 layers):
# - cladding
# - intermediate sheathing
# - composite insulating/framing
# - interior finish
a = dict(clad={}, sheath={}, compo={}, finish={}, glazing={})
if specs["type"] == "shading":
mt = "material"
d = 0.015
a["compo"]["mat"] = mats()[mt]
a["compo"]["d" ] = d
a["compo"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
elif specs["type"] == "partition":
if not specs["clad"] == "none":
mt = "drywall"
d = 0.015
a["clad"]["mat"] = mats()[mt]
a["clad"]["d" ] = d
a["clad"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
mt = "concrete"
d = 0.015
if specs["frame"] == "light": mt = "material"
if u: mt = "mineral"
if specs["frame"] == "medium": d = 0.100
if specs["frame"] == "heavy": d = 0.200
if u: d = 0.100
a["compo"]["mat"] = mats()[mt]
a["compo"]["d" ] = d
a["compo"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
if not specs["finish"] == "none":
mt = "drywall"
d = 0.015
a["finish"]["mat"] = mats()[mt]
a["finish"]["d" ] = d
a["finish"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
elif specs["type"] == "wall":
if not specs["clad"] == "none":
mt = "material"
d = 0.100
if specs["clad"] == "medium": mt = "brick"
if specs["clad"] == "heavy": mt = "concrete"
if specs["clad"] == "light": d = 0.015
a["clad"]["mat"] = mats()[mt]
a["clad"]["d" ] = d
a["clad"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
mt = "drywall"
d = 0.100
if specs["frame"] == "medium": mt = "mineral"
if specs["frame"] == "heavy": mt = "polyiso"
if specs["frame"] == "light": d = 0.015
a["sheath"]["mat"] = mats()[mt]
a["sheath"]["d" ] = d
a["sheath"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
mt = "mineral"
d = 0.100
if specs["frame"] == "medium": mt = "cellulose"
if specs["frame"] == "heavy": mt = "concrete"
if not u: mt = "material"
if specs["frame"] == "heavy": d = 0.200
if not u: d = 0.015
a["compo"]["mat"] = mats()[mt]
a["compo"]["d" ] = d
a["compo"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
if not specs["finish"] == "none":
mt = "concrete"
d = 0.015
if specs["finish"] == "light": mt = "drywall"
if specs["finish"] == "medium": d = 0.100
if specs["finish"] == "heavy": d = 0.200
a["finish"]["mat"] = mats()[mt]
a["finish"]["d" ] = d
a["finish"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
elif specs["type"] == "roof":
if not specs["clad"] == "none":
mt = "concrete"
d = 0.015
if specs["clad"] == "light": mt = "material"
if specs["clad"] == "medium": d = 0.100 # e.g. terrace
if specs["clad"] == "heavy": d = 0.200 # e.g. parking garage
a["clad"]["mat"] = mats()[mt]
a["clad"]["d" ] = d
a["clad"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
mt = "mineral"
d = 0.100
if specs["frame"] == "medium": mt = "polyiso"
if specs["frame"] == "heavy": mt = "cellulose"
if not u: mt = "material"
if not u: d = 0.015
a["compo"]["mat"] = mats()[mt]
a["compo"]["d" ] = d
a["compo"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
if not specs["finish"] == "none":
mt = "concrete"
d = 0.015
if specs["finish"] == "light": mt = "drywall"
if specs["finish"] == "medium": d = 0.100 # proxy for steel decking
if specs["finish"] == "heavy": d = 0.200
a["finish"]["mat"] = mats()[mt]
a["finish"]["d" ] = d
a["finish"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
elif specs["type"] == "floor":
if not specs["clad"] == "none":
mt = "material"
d = 0.015
a["clad"]["mat"] = mats()[mt]
a["clad"]["d" ] = d
a["clad"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
mt = "mineral"
d = 0.100
if specs["frame"] == "medium": mt = "polyiso"
if specs["frame"] == "heavy": mt = "cellulose"
if not u: mt = "material"
if not u: d = 0.015
a["compo"]["mat"] = mats()[mt]
a["compo"]["d" ] = d
a["compo"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
if not specs["finish"] == "none":
mt = "concrete"
d = 0.015
if specs["finish"] == "light": mt = "material"
if specs["finish"] == "medium": d = 0.100
if specs["finish"] == "heavy": d = 0.200
a["finish"]["mat"] = mats()[mt]
a["finish"]["d" ] = d
a["finish"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
elif specs["type"] == "slab":
mt = "sand"
d = 0.100
a["clad"]["mat"] = mats()[mt]
a["clad"]["d" ] = d
a["clad"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
if not specs["frame"] == "none":
mt = "polyiso"
d = 0.025
a["sheath"]["mat"] = mats()[mt]
a["sheath"]["d" ] = d
a["sheath"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
mt = "concrete"
d = 0.100
if specs["frame"] == "heavy": d = 0.200
a["compo"]["mat"] = mats()[mt]
a["compo"]["d" ] = d
a["compo"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
if not specs["finish"] == "none":
mt = "material"
d = 0.015
a["finish"]["mat"] = mats()[mt]
a["finish"]["d" ] = d
a["finish"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
elif specs["type"] == "basement":
if not specs["clad"] == "none":
mt = "concrete"
d = 0.100
if specs["clad"] == "light": mt = "material"
if specs["clad"] == "light": d = 0.015
a["clad"]["mat"] = mats[mt]
a["clad"]["d" ] = d
a["clad"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
mt = "polyiso"
d = 0.025
a["sheath"]["mat"] = mats()[mt]
a["sheath"]["d" ] = d
a["sheath"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
mt = "concrete"
d = 0.200
a["compo"]["mat"] = mats()[mt]
a["compo"]["d" ] = d
a["compo"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
else:
mt = "concrete"
d = 0.200
a["sheath"]["mat"] = mats()[mt]
a["sheath"]["d" ] = d
a["sheath"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
if not specs["finish"] == "none":
mt = "mineral"
d = 0.075
a["compo"]["mat"] = mats()[mt]
a["compo"]["d" ] = d
a["compo"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
mt = "drywall"
d = 0.015
a["finish"]["mat"] = mats()[mt]
a["finish"]["d" ] = d
a["finish"]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
elif specs["type"] == "door":
mt = "door"
d = 0.045
a["compo" ]["mat" ] = mats()[mt]
a["compo" ]["d" ] = d
a["compo" ]["id" ] = "OSut." + mt + ".%03d" % int(d * 1000)
elif specs["type"] == "window":
a["glazing"]["u" ] = u if u else uo()["window"]
a["glazing"]["shgc"] = 0.450
if "shgc" in specs: a["glazing"]["shgc"] = specs["shgc"]
a["glazing"]["id" ] = "OSut.window"
a["glazing"]["id" ] += ".U%.1f" % a["glazing"]["u"]
a["glazing"]["id" ] += ".SHGC%d" % (a["glazing"]["shgc"]*100)
elif specs["type"] == "skylight":
a["glazing"]["u" ] = u if u else uo()["skylight"]
a["glazing"]["shgc"] = 0.450
if "shgc" in specs: a["glazing"]["shgc"] = specs["shgc"]
a["glazing"]["id" ] = "OSut.skylight"
a["glazing"]["id" ] += ".U%.1f" % a["glazing"]["u"]
a["glazing"]["id" ] += ".SHGC%d" % (a["glazing"]["shgc"]*100)
if a["glazing"]:
layers = openstudio.model.FenestrationMaterialVector()
u0 = a["glazing"]["u" ]
shgc = a["glazing"]["shgc"]
lyr = model.getSimpleGlazingByName(a["glazing"]["id"])
if lyr:
lyr = lyr.get()
else:
lyr = openstudio.model.SimpleGlazing(model, u0, shgc)
lyr.setName(a["glazing"]["id"])
layers.append(lyr)
else:
layers = openstudio.model.OpaqueMaterialVector()
# Loop through each layer spec, and generate construction.
for i, l in a.items():
if not l: continue
lyr = model.getStandardOpaqueMaterialByName(l["id"])
if lyr:
lyr = lyr.get()
else:
lyr = openstudio.model.StandardOpaqueMaterial(model)
lyr.setName(l["id"])
lyr.setThickness(l["d"])
if "rgh" in l["mat"]: lyr.setRoughness(l["mat"]["rgh"])
if "k" in l["mat"]: lyr.setConductivity(l["mat"]["k"])
if "rho" in l["mat"]: lyr.setDensity(l["mat"]["rho"])
if "cp" in l["mat"]: lyr.setSpecificHeat(l["mat"]["cp" ])
if "thm" in l["mat"]: lyr.setThermalAbsorptance(l["mat"]["thm"])
if "sol" in l["mat"]: lyr.setSolarAbsorptance(l["mat"]["sol"])
if "vis" in l["mat"]: lyr.setVisibleAbsorptance(l["mat"]["vis"])
layers.append(lyr)
c = openstudio.model.Construction(layers)
c.setName(ide)
# Adjust insulating layer thickness or conductivity to match requested Uo.
if u and not a["glazing"]:
ro = 1 / u - flm
if ro > 0:
if specs["type"] == "door": # 1x layer, adjust conductivity
layer = c.getLayer(0).to_StandardOpaqueMaterial()
if not layer:
return oslg.invalid(id + " standard material?", mth, 0)
layer = layer.get()
k = layer.thickness() / ro
layer.setConductivity(k)
else: # multiple layers, adjust insulating layer thickness
lyr = insulatingLayer(c)
if not lyr["index"] or not lyr["type"] or not lyr["r"]:
return oslg.invalid(id + " construction", mth, 0)
index = lyr["index"]
layer = c.getLayer(index).to_StandardOpaqueMaterial()
if not layer:
return oslg.invalid(id + " material %d" % index, mth, 0)
layer = layer.get()
k = layer.conductivity()
d = (ro - rsi(c) + lyr["r"]) * k
if d < 0.03:
m = id + " adjusted material thickness"
return oslg.invalid(m, mth, 0)
nom = re.sub(r'[^a-zA-Z]', '', layer.nameString())
nom = re.sub(r'OSut', '', nom)
nom = "OSut." + nom + ".%03d" % int(d * 1000)
if model.getStandardOpaqueMaterialByName(nom):
omat = model.getStandardOpaqueMaterialByName(nom).get()
c.setLayer(index, omat)
else:
layer.setName(nom)
layer.setThickness(d)
return c
def genShade(subs=None) -> bool:
"""Generates solar shade(s) (e.g. roller, textile) for glazed OpenStudio
SubSurfaces (v321+), controlled to minimize overheating in cooling months
(May to October in Northern Hemisphere), when outdoor dry bulb temperature
is above 18°C and impinging solar radiation is above 100 W/m2.
Args:
subs:
A list of sub surfaces.
Returns:
True: If shade successfully generated.
False: If invalid input (see logs).
"""
# Filter OpenStudio warnings for ShadingControl:
# ref: https://github.com/NREL/OpenStudio/issues/4911
# str = ".*(?<!ShadingControl)$"
# openstudio.Logger().instance().standardOutLogger().setChannelRegex(str)
mth = "osut.genShade"
cl = openstudio.model.SubSurfaceVector
if int("".join(openstudio.openStudioVersion().split("."))) < 321:
return False
if not isinstance(subs, cl):
return oslg.mismatch("subs", subs, cl, mth, CN.DBG, False)
if not subs:
return oslg.empty("subs", mth, CN.WRN, False)
# Shading availability period.
model = subs[0].model()
ide = "onoff"
onoff = model.getScheduleTypeLimitsByName(ide)
if onoff:
onoff = onoff.get()
else:
onoff = openstudio.model.ScheduleTypeLimits(model)
onoff.setName(ide)
onoff.setLowerLimitValue(0)
onoff.setUpperLimitValue(1)
onoff.setNumericType("Discrete")
onoff.setUnitType("Availability")
# Shading schedule.
ide = "OSut.SHADE.Ruleset"
sch = model.getScheduleRulesetByName(ide)
if sch:
sch = sch.get()
else:
sch = openstudio.model.ScheduleRuleset(model, 0)
sch.setName(ide)
sch.setScheduleTypeLimits(onoff)
sch.defaultDaySchedule().setName("OSut.SHADE.Ruleset.Default")
# Summer cooling rule.
ide = "OSut.SHADE.ScheduleRule"
rule = model.getScheduleRuleByName(ide)
if rule:
rule = rule.get()
else:
may = openstudio.MonthOfYear("May")
october = openstudio.MonthOfYear("Oct")
start = openstudio.Date(may, 1)
finish = openstudio.Date(october, 31)
rule = openstudio.model.ScheduleRule(sch)
rule.setName(ide)
rule.setStartDate(start)
rule.setEndDate(finish)
rule.setApplyAllDays(True)
rule.daySchedule().setName("OSut.SHADE.Rule.Default")
rule.daySchedule().addValue(openstudio.Time(0,24,0,0), 1)
# Shade object.
ide = "OSut.SHADE"
shd = model.getShadeByName(ide)
if shd:
shd = shd.get()
else:
shd = openstudio.model.Shade(model)
shd.setName(ide)
# Shading control (unique to each call).
ide = "OSut.ShadingControl"
ctl = openstudio.model.ShadingControl(shd)
ctl.setName(ide)
ctl.setSchedule(sch)
ctl.setShadingControlType("OnIfHighOutdoorAirTempAndHighSolarOnWindow")
ctl.setSetpoint(18) # °C
ctl.setSetpoint2(100) # W/m2
ctl.setMultipleSurfaceControlType("Group")
ctl.setSubSurfaces(subs)
return True
def genMass(sps=None, ratio=2.0) -> bool:
""" Generates an internal mass definition and instances for target spaces.
This is largely adapted from OpenStudio-Standards:
https://github.com/NREL/openstudio-standards/blob/
eac3805a65be060b39ecaf7901c908f8ed2c051b/lib/openstudio-standards/
prototypes/common/objects/Prototype.Model.rb#L572
Args:
sps (OpenStudio::Model::SpaceVector):
Target spaces.
ratio (float):
Ratio of internal mass surface area to floor surface area.
Returns:
bool: Whether successfully generated.
False: If invalid inputs (see logs).
"""
mth = "osut.genMass"
cl = openstudio.model.SpaceVector
if not isinstance(sps, cl):
return oslg.mismatch("spaces", sps, cl, mth, CN.DBG, False)
try:
ratio = float(ratio)
except:
return oslg.mismatch("ratio", ratio, float, mth, CN.DBG, False)
if not sps:
return oslg.empty("spaces", mth, CN.DBG, False)
if ratio < 0:
return oslg.negative("ratio", mth, CN.ERR, False)
# A single material.
mdl = sps[0].model()
ide = "OSut.MASS.Material"
mat = mdl.getOpaqueMaterialByName(ide)
if mat:
mat = mat.get()
else:
mat = openstudio.model.StandardOpaqueMaterial(mdl)
mat.setName(ide)
mat.setRoughness("MediumRough")
mat.setThickness(0.15)
mat.setConductivity(1.12)
mat.setDensity(540)
mat.setSpecificHeat(1210)
mat.setThermalAbsorptance(0.9)
mat.setSolarAbsorptance(0.7)
mat.setVisibleAbsorptance(0.17)
# A single, 1x layered construction.
ide = "OSut.MASS.Construction"
con = mdl.getConstructionByName(ide)
if con:
con = con.get()
else:
con = openstudio.model.Construction(mdl)
con.setName(ide)
layers = openstudio.model.MaterialVector()
layers.append(mat)
con.setLayers(layers)
ide = "OSut.InternalMassDefinition.%.2f" % ratio
df = mdl.getInternalMassDefinitionByName(ide)
if df:
df = df.get
else:
df = openstudio.model.InternalMassDefinition(mdl)
df.setName(ide)
df.setConstruction(con)
df.setSurfaceAreaperSpaceFloorArea(ratio)
for sp in sps:
mass = openstudio.model.InternalMass(df)
mass.setName("OSut.InternalMass.%s" % sp.nameString())
mass.setSpace(sp)
return True
def holdsConstruction(cset=None, base=None, gr=False, ex=False, type=""):
"""Validates whether a default construction set holds a base construction.
Args:
cset (openstudio.model.DefaultConstructionSet):
A default construction set.
base (openstudio.model.ConstructionBase):
A construction base.
gr (bool):
Whether ground-facing surface.
ex (bool):
Whether exterior-facing surface.
type:
An OpenStudio surface (or sub surface) type (e.g. "Wall").
Returns:
bool: Whether default set holds construction.
False: If invalid input (see logs).
"""
mth = "osut.holdsConstruction"
cl1 = openstudio.model.DefaultConstructionSet
cl2 = openstudio.model.ConstructionBase
t1 = openstudio.model.Surface.validSurfaceTypeValues()
t2 = openstudio.model.SubSurface.validSubSurfaceTypeValues()
t1 = [t.lower() for t in t1]
t2 = [t.lower() for t in t2]
c = None
if not isinstance(cset, cl1):
return oslg.mismatch("set", cset, cl1, mth, CN.DBG, False)
if not isinstance(base, cl2):
return oslg.mismatch("base", base, cl2, mth, CN.DBG, False)
if not isinstance(gr, bool):
return oslg.mismatch("ground", gr, bool, mth, CN.DBG, False)
if not isinstance(ex, bool):
return oslg.mismatch("exterior", ex, bool, mth, CN.DBG, False)
try:
type = str(type)
except:
return oslg.mismatch("surface type", type, str, mth, CN.DBG, False)
type = type.lower()
if type in t1:
if gr:
if cset.defaultGroundContactSurfaceConstructions():
c = cset.defaultGroundContactSurfaceConstructions().get()
elif ex:
if cset.defaultExteriorSurfaceConstructions():
c = cset.defaultExteriorSurfaceConstructions().get()
else:
if cset.defaultInteriorSurfaceConstructions():
c = cset.defaultInteriorSurfaceConstructions().get()
elif type in t2:
if gr:
return False
if ex:
if cset.defaultExteriorSubSurfaceConstructions():
c = cset.defaultExteriorSubSurfaceConstructions().get()
else:
if cset.defaultInteriorSubSurfaceConstructions():
c = cset.defaultInteriorSubSurfaceConstructions().get()
else:
return oslg.invalid("surface type", mth, 5, CN.DBG, False)
if c is None: return False
if type in t1:
if type == "roofceiling":
if c.roofCeilingConstruction():
if c.roofCeilingConstruction().get() == base: return True
elif type == "floor":
if c.floorConstruction():
if c.floorConstruction().get() == base: return True
else: # "wall"
if c.wallConstruction():
if c.wallConstruction().get() == base: return True
else: # t2
if type == "tubulardaylightdiffuser":
if c.tubularDaylightDiffuserConstruction():
if c.tubularDaylightDiffuserConstruction() == base: return True
elif type == "tubulardaylightdome":
if c.tubularDaylightDomeConstruction():
if c.tubularDaylightDomeConstruction().get() == base: return True
elif type == "skylight":
if c.overheadDoorConstruction():
if c.overheadDoorConstruction().get() == base: return True
elif type == "glassdoor":
if c.glassDoorConstruction():
if c.glassDoorConstruction().get() == base: return True
elif type == "door":
if c.doorConstruction():
if c.doorConstruction().get() == base: return True
elif type == "operablewindow":
if c.operableWindowConstruction():
if c.operableWindowConstruction().get() == base: return True
else: # "fixedwindow"
if c.fixedWindowConstruction():
if c.fixedWindowConstruction().get() == base: return True
return False
def defaultConstructionSet(s=None):
"""Returns a surface's default construction set.
Args:
s (openstudio.model.Surface):
A surface.
Returns:
openstudio.model.DefaultConstructionSet: A default construction set.
None: If invalid inputs (see logs).
"""
mth = "osut.defaultConstructionSet"
cl = openstudio.model.Surface
if not isinstance(s, cl):
return oslg.mismatch("surface", s, cl, mth)
if not s.isConstructionDefaulted():
oslg.log(CN.WRN, "construction not defaulted (%s)" % mth)