From f2171c29b8605d7a61c19f5d1a810bb8e73c2925 Mon Sep 17 00:00:00 2001 From: Samuel Letellier-Duchesne Date: Wed, 10 Aug 2022 18:13:36 -0400 Subject: [PATCH] An issue with the rotation of buildings with Site shading objects has been fixed (#373) Issue occurs when Zones have an angle relative to north different than 0 --- archetypal/idfclass/idf.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/archetypal/idfclass/idf.py b/archetypal/idfclass/idf.py index 4df75ef1..585cbdb6 100644 --- a/archetypal/idfclass/idf.py +++ b/archetypal/idfclass/idf.py @@ -2459,6 +2459,16 @@ def to_world(self): if all(angle != 0 for angle in zone_angles): self.rotate(None, (0, 0, 0)) + from geomeppy.recipes import rotate + + # Since we rotated the building and the site, we need to rotate the site + # back by angle + anchor = Vector3D(*(0, 0, 0)) + shadingsurfaces = self.getsiteshadingsurfaces() + self.translate(-anchor) + rotate(shadingsurfaces, next(iter(zone_angles))) + self.translate(anchor) + zone_origin = { zone.Name.upper(): Vector3D(zone.X_Origin, zone.Y_Origin, zone.Z_Origin) for zone in self.idfobjects["ZONE"] @@ -2468,6 +2478,10 @@ def to_world(self): daylighting_refpoints = [ p for p in self.idfobjects["DAYLIGHTING:REFERENCEPOINT"] ] + attached_shading_surf_names = [] + for g in self.idd_index["ref2names"]["AttachedShadingSurfNames"]: + for item in self.idfobjects[g]: + attached_shading_surf_names.append(item) # Translate surfaces in the direction of their zone's origin vector. for subsurf in subsurfaces: @@ -2483,6 +2497,10 @@ def to_world(self): day.YCoordinate_of_Reference_Point, day.ZCoordinate_of_Reference_Point, ) = coords[0] + for attached_surf in attached_shading_surf_names: + parent_surface = attached_surf.get_referenced_object("Base_Surface_Name") + zone_name = parent_surface.Zone_Name + translate([attached_surf], zone_origin[zone_name.upper()]) # Edit the `GLOBALGEOMETRYRULES` to "World" for obj in self.idfobjects["GLOBALGEOMETRYRULES"]: @@ -2556,11 +2574,12 @@ def rotate( from geomeppy.geom.vectors import Vector3D anchor = Vector3D(*anchor) + # Rotate the building + super(IDF, self).rotate(angle, anchor=anchor) log( f"Geometries rotated by {angle} degrees around " f"{anchor or 'building centroid'}" ) - super(IDF, self).rotate(angle, anchor=anchor) # after building is rotate, change the north axis and zone direction to zero. self.idfobjects["BUILDING"][0].North_Axis = 0 @@ -2597,6 +2616,19 @@ def rotated(self): def rotated(self, value): self._rotated = bool(value) + def getsiteshadingsurfaces(self, surface_type=""): + site_shading_types = self.idd_index["ref2names"][ + "AllShadingSurfNames" + ].difference(self.idd_index["ref2names"]["AttachedShadingSurfNames"]) + surfaces = itertools.chain.from_iterable( + [self.idfobjects[key.upper()] for key in site_shading_types] + ) + if surface_type: + surfaces = filter( + lambda x: x.Surface_Type.lower() == surface_type.lower(), surfaces + ) + return list(surfaces) + def _process_csv(file, working_dir, simulname): """Process csv file.