Skip to content

Commit 48749ef

Browse files
committed
Extends holdsConstruction - done
1 parent 992ce8c commit 48749ef

File tree

2 files changed

+120
-70
lines changed

2 files changed

+120
-70
lines changed

src/osut/osut.py

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ def holdsConstruction(set=None, base=None, gr=False, ex=False, type=""):
790790
ex (bool):
791791
Whether exterior-facing surface.
792792
type:
793-
A surface type ("Wall", "Floor", "RoofCeiling").
793+
An OpenStudio surface (or sub surface) type (e.g. "Wall").
794794
795795
Returns:
796796
bool: Whether default set holds construction.
@@ -804,15 +804,16 @@ def holdsConstruction(set=None, base=None, gr=False, ex=False, type=""):
804804
t2 = openstudio.model.SubSurface.validSubSurfaceTypeValues()
805805
t1 = [t.lower() for t in t1]
806806
t2 = [t.lower() for t in t2]
807+
c = None
807808

808809
if not isinstance(set, cl1):
809810
return oslg.mismatch("set", set, cl1, mth, CN.DBG, False)
810811
if not isinstance(base, cl2):
811812
return oslg.mismatch("base", base, cl2, mth, CN.DBG, False)
812-
if gr not in [True, False]:
813-
return oslg.invalid("ground", mth, 3, CN.DBG, False)
814-
if ex not in [True, False]:
815-
return oslg.invalid("exterior", mth, 4, CN.DBG, False)
813+
if not isinstance(gr, bool):
814+
return oslg.mismatch("ground", gr, bool, mth, CN.DBG, False)
815+
if not isinstance(ex, bool):
816+
return oslg.mismatch("exterior", ex, bool, mth, CN.DBG, False)
816817

817818
try:
818819
type = str(type)
@@ -821,35 +822,62 @@ def holdsConstruction(set=None, base=None, gr=False, ex=False, type=""):
821822

822823
type = type.lower()
823824

824-
if type not in (t1 + t2):
825+
if type in t1:
826+
if gr:
827+
if set.defaultGroundContactSurfaceConstructions():
828+
c = set.defaultGroundContactSurfaceConstructions().get()
829+
elif ex:
830+
if set.defaultExteriorSurfaceConstructions():
831+
c = set.defaultExteriorSurfaceConstructions().get()
832+
else:
833+
if set.defaultInteriorSurfaceConstructions():
834+
c = set.defaultInteriorSurfaceConstructions().get()
835+
elif type in t2:
836+
if gr:
837+
return False
838+
if ex:
839+
if set.defaultExteriorSubSurfaceConstructions():
840+
c = set.defaultExteriorSubSurfaceConstructions().get()
841+
else:
842+
if set.defaultInteriorSubSurfaceConstructions():
843+
c = set.defaultInteriorSubSurfaceConstructions().get()
844+
else:
825845
return oslg.invalid("surface type", mth, 5, CN.DBG, False)
826846

827-
constructions = None
828-
829-
if gr:
830-
if set.defaultGroundContactSurfaceConstructions():
831-
constructions = set.defaultGroundContactSurfaceConstructions().get()
832-
elif ex:
833-
if set.defaultExteriorSurfaceConstructions():
834-
constructions = set.defaultExteriorSurfaceConstructions().get()
835-
else:
836-
if set.defaultInteriorSurfaceConstructions():
837-
constructions = set.defaultInteriorSurfaceConstructions().get()
838-
839-
if not constructions: return False
840-
841-
if type == "roofceiling":
842-
if constructions.roofCeilingConstruction():
843-
construction = constructions.roofCeilingConstruction().get()
844-
if construction == base: return True
845-
elif type == "floor":
846-
if constructions.floorConstruction():
847-
construction = constructions.floorConstruction().get()
848-
if construction == base: return True
849-
else:
850-
if constructions.wallConstruction():
851-
construction = constructions.wallConstruction().get()
852-
if construction == base: return True
847+
if not c: return False
848+
849+
if type in t1:
850+
if type == "roofceiling":
851+
if c.roofCeilingConstruction():
852+
if c.roofCeilingConstruction().get() == base: return True
853+
elif type == "floor":
854+
if c.floorConstruction():
855+
if c.floorConstruction().get() == base: return True
856+
else: # "wall"
857+
if c.wallConstruction():
858+
if c.wallConstruction().get() == base: return True
859+
else: # t2
860+
if type == "tubulardaylightdiffuser":
861+
if c.tubularDaylightDiffuserConstruction():
862+
if c.tubularDaylightDiffuserConstruction() == base: return True
863+
elif type == "tubulardaylightdome":
864+
if c.tubularDaylightDomeConstruction():
865+
if c.tubularDaylightDomeConstruction().get() == base: return True
866+
elif type == "skylight":
867+
if c.overheadDoorConstruction():
868+
if c.overheadDoorConstruction().get() == base: return True
869+
elif type == "glassdoor":
870+
if c.glassDoorConstruction():
871+
if c.glassDoorConstruction().get() == base: return True
872+
elif type == "door":
873+
if c.doorConstruction():
874+
if c.doorConstruction().get() == base: return True
875+
elif type == "operablewindow":
876+
if c.operableWindowConstruction():
877+
if c.operableWindowConstruction().get() == base: return True
878+
else: # "fixedwindow"
879+
if c.fixedWindowConstruction():
880+
if c.fixedWindowConstruction().get() == base: return True
853881

854882
return False
855883

@@ -1180,7 +1208,7 @@ def is_spandrel(s=None):
11801208

11811209
val = val.get()
11821210

1183-
if val not in [True, False]:
1211+
if not isinstance(val, bool):
11841212
return invalid("spandrel bool", mth, 1, CN.ERR, False)
11851213

11861214
return val
@@ -1419,7 +1447,7 @@ def is_same_vtx(s1=None, s2=None, indexed=True) -> bool:
14191447
if not s1: return False
14201448
if not s2: return False
14211449
if len(s1) != len(s2): return False
1422-
if indexed not in [True, False]: indexed = True
1450+
if not isinstance(indexed, bool): indexed = True
14231451

14241452
if indexed:
14251453
xOK = abs(s1[0].x() - s2[0].x()) < CN.TOL

tests/test_osut.py

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -875,66 +875,88 @@ def test08_holds_constructions(self):
875875
model = model.get()
876876
mdl = openstudio.model.Model()
877877

878-
t1 = "roofceiling"
879-
t2 = "wall"
880-
cl1 = openstudio.model.DefaultConstructionSet
881-
cl2 = openstudio.model.LayeredConstruction
882-
id1 = cl1.__name__
883-
id2 = cl2.__name__
884-
n1 = "CBECS Before-1980 ClimateZone 8 (smoff) ConstSet"
885-
n2 = "CBECS Before-1980 ExtRoof IEAD ClimateZone 8"
886-
m5 = "Invalid 'surface type' arg #5 (osut.holdsConstruction)"
887-
m6 = "'set' LayeredConstruction? expecting DefaultConstructionSet"
888-
m7 = "'set' Model? expecting DefaultConstructionSet"
889-
set = model.getDefaultConstructionSetByName(n1)
890-
c = model.getLayeredConstructionByName(n2)
878+
# cl1 = openstudio.model.DefaultConstructionSet
879+
# cl2 = openstudio.model.LayeredConstruction
880+
# cl2 = openstudio.model.Construction
881+
# id1 = cl1.__name__
882+
# id2 = cl2.__name__
883+
# id3 = cl3.__name__
884+
885+
t1 = "RoofCeiling"
886+
t2 = "Wall"
887+
t3 = "Floor"
888+
t4 = "FixedWindow"
889+
n0 = "CBECS Before-1980 ClimateZone 8 (smoff) ConstSet"
890+
n1 = "CBECS Before-1980 ExtRoof IEAD ClimateZone 8"
891+
n2 = "CBECS Before-1980 ExtWall Mass ClimateZone 8"
892+
n3 = "000 ExtSlabCarpet 4in ClimateZone 1-8"
893+
n4 = "CBECS Before-1980 ExtWindow ClimateZone 5-8"
894+
m1 = "Invalid 'surface type' arg #5 (osut.holdsConstruction)"
895+
m2 = "'set' LayeredConstruction? expecting DefaultConstructionSet"
896+
m3 = "'set' Model? expecting DefaultConstructionSet"
897+
898+
set = model.getDefaultConstructionSetByName(n0)
899+
c1 = model.getLayeredConstructionByName(n1)
900+
c2 = model.getLayeredConstructionByName(n2)
901+
c3 = model.getLayeredConstructionByName(n3)
902+
c4 = model.getLayeredConstructionByName(n4)
891903
self.assertTrue(set)
892-
self.assertTrue(c)
904+
self.assertTrue(c1)
905+
self.assertTrue(c2)
906+
self.assertTrue(c3)
907+
self.assertTrue(c4)
893908
set = set.get()
894-
c = c.get()
909+
c1 = c1.get()
910+
c2 = c2.get()
911+
c3 = c3.get()
912+
c4 = c4.get()
895913

896-
# TRUE case: 'set' holds 'c' (exterior roofceiling construction).
897-
answer = osut.holdsConstruction(set, c, False, True, t1)
898-
self.assertTrue(osut.holdsConstruction(set, c, False, True, t1))
899-
self.assertEqual(o.status(), 0)
914+
# TRUE cases:
915+
self.assertTrue(osut.holdsConstruction(set, c1, False, True, t1))
916+
self.assertTrue(osut.holdsConstruction(set, c2, False, True, t2))
917+
self.assertTrue(osut.holdsConstruction(set, c3, True, False, t3))
918+
self.assertTrue(osut.holdsConstruction(set, c4, False, True, t4))
919+
920+
# FALSE case: roofceiling as ground roof construction.
921+
self.assertFalse(osut.holdsConstruction(set, c1, True, False, t1))
900922

901-
# FALSE case: not ground construction.
902-
self.assertFalse(osut.holdsConstruction(set, c, True, True, t1))
923+
# FALSE case: ground-facing sub subsurface.
924+
self.assertFalse(osut.holdsConstruction(set, c4, True, False, t4))
903925
self.assertEqual(o.status(), 0)
904926

905-
# INVALID case: arg #5 : None (instead of surface type string).
906-
self.assertFalse(osut.holdsConstruction(set, c, True, True, None))
927+
# INVALID case: arg #1 : None (instead of surface type string).
928+
self.assertFalse(osut.holdsConstruction(set, c1, False, True, None))
907929
self.assertTrue(o.is_debug())
908930
self.assertEqual(len(o.logs()), 1)
909-
self.assertEqual(o.logs()[0]["message"], m5)
931+
self.assertEqual(o.logs()[0]["message"], m1)
910932
self.assertEqual(o.clean(), DBG)
911933

912-
# INVALID case: arg #5 : empty surface type string.
913-
self.assertFalse(osut.holdsConstruction(set, c, True, True, ""))
934+
# INVALID case: arg #2 : empty surface type string.
935+
self.assertFalse(osut.holdsConstruction(set, c1, False, True, ""))
914936
self.assertTrue(o.is_debug())
915937
self.assertEqual(len(o.logs()), 1)
916-
self.assertEqual(o.logs()[0]["message"], m5)
938+
self.assertEqual(o.logs()[0]["message"], m1)
917939
self.assertEqual(o.clean(), DBG)
918940

919-
# INVALID case: arg #5 : c construction (instead of surface type string).
920-
self.assertFalse(osut.holdsConstruction(set, c, True, True, c))
941+
# INVALID case: arg #3 : construction (instead of surface type string).
942+
self.assertFalse(osut.holdsConstruction(set, c1, False, True, c2))
921943
self.assertTrue(o.is_debug())
922944
self.assertEqual(len(o.logs()), 1)
923-
self.assertEqual(o.logs()[0]["message"], m5)
945+
self.assertEqual(o.logs()[0]["message"], m1)
924946
self.assertEqual(o.clean(), DBG)
925947

926-
# INVALID case: arg #1 : c construction (instead of surface type string).
927-
self.assertFalse(osut.holdsConstruction(c, c, True, True, c))
948+
# INVALID case: arg #4 : construction (instead of set).
949+
self.assertFalse(osut.holdsConstruction(c2, c1, False, True, t1))
928950
self.assertTrue(o.is_debug())
929951
self.assertEqual(len(o.logs()), 1)
930-
self.assertTrue(m6 in o.logs()[0]["message"])
952+
self.assertTrue(m2 in o.logs()[0]["message"])
931953
self.assertEqual(o.clean(), DBG)
932954

933-
# INVALID case: arg #1 : model (instead of surface type string).
934-
self.assertFalse(osut.holdsConstruction(mdl, c, True, True, t1))
955+
# INVALID case: arg #5 : model (instead of set).
956+
self.assertFalse(osut.holdsConstruction(mdl, c1, False, True, t1))
935957
self.assertTrue(o.is_debug())
936958
self.assertEqual(len(o.logs()), 1)
937-
self.assertTrue(m7 in o.logs()[0]["message"])
959+
self.assertTrue(m3 in o.logs()[0]["message"])
938960
self.assertEqual(o.clean(), DBG)
939961

940962
del(model)

0 commit comments

Comments
 (0)