Skip to content

Commit

Permalink
Add new method to resize building to width and length (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Letellier-Duchesne authored Aug 30, 2021
1 parent 54dfc1e commit bd97a8f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
38 changes: 34 additions & 4 deletions archetypal/idfclass/idf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,8 @@ def simulate(self, **kwargs):
# Todo: Add EpMacro Thread -> if exist in.imf "%program_path%EPMacro"
# Run the expandobjects program if necessary
tmp = (
self.output_directory.makedirs_p() / "expandobjects_run_" + str(uuid.uuid1())[0:8]
self.output_directory.makedirs_p() / "expandobjects_run_"
+ str(uuid.uuid1())[0:8]
).mkdir()
# Run the ExpandObjects preprocessor program
expandobjects_thread = ExpandObjectsThread(self, tmp)
Expand All @@ -1347,7 +1348,8 @@ def simulate(self, **kwargs):

# Run the Basement preprocessor program if necessary
tmp = (
self.output_directory.makedirs_p() / "runBasement_run_" + str(uuid.uuid1())[0:8]
self.output_directory.makedirs_p() / "runBasement_run_"
+ str(uuid.uuid1())[0:8]
).mkdir()
basement_thread = BasementThread(self, tmp)
basement_thread.start()
Expand All @@ -1360,7 +1362,9 @@ def simulate(self, **kwargs):
raise e

# Run the Slab preprocessor program if necessary
tmp = (self.output_directory.makedirs_p() / "runSlab_run_" + str(uuid.uuid1())[0:8]).mkdir()
tmp = (
self.output_directory.makedirs_p() / "runSlab_run_" + str(uuid.uuid1())[0:8]
).mkdir()
slab_thread = SlabThread(self, tmp)
slab_thread.start()
slab_thread.join()
Expand All @@ -1372,7 +1376,9 @@ def simulate(self, **kwargs):
raise e

# Run the energyplus program
tmp = (self.output_directory.makedirs_p() / "eplus_run_" + str(uuid.uuid1())[0:8]).mkdir()
tmp = (
self.output_directory.makedirs_p() / "eplus_run_" + str(uuid.uuid1())[0:8]
).mkdir()
running_simulation_thread = EnergyPlusThread(self, tmp)
running_simulation_thread.start()
running_simulation_thread.join()
Expand Down Expand Up @@ -2055,6 +2061,30 @@ def _get_used_schedules(self, yearly_only=False):
pass
return used_schedules

@property
def width(self):
"""Get the width of the building [m]."""
bbox = self.bounding_box()
return max(bbox.xs) - min(bbox.xs)

@property
def length(self):
"""Get the length of the building [m]."""
bbox = self.bounding_box()
return max(bbox.ys) - min(bbox.ys)

def resize(self, width, length):
"""Resize the floor plate to x and y [meters].
Args:
width (float): The new width [m] of the building (x axis).
length (float): The new length [m] of the building (y axis).
"""
x_scale = width / self.width
y_scale = length / self.length
self.scale(x_scale, axes="x")
self.scale(y_scale, axes="y")

def rename(self, objkey, objname, newname):
"""Rename all the references to this objname.
Expand Down
9 changes: 9 additions & 0 deletions tests/test_idfclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ def test_save(self, idf, tmp_path):
save_as = tmp_path / "idf_dup.idf"
idf_dup = idf.saveas(save_as)

def test_resize(self):
"""Test resizing a building to specific width and length"""
idf = IDF.from_example_files("5ZoneAirCooled.idf")
assert idf.width == 30.5
assert idf.length == 15.2
idf.resize(10, 10)
assert idf.width == 10
assert idf.length == 10


class TestIDFTransition:
def test_transition(self, tmp_path):
Expand Down

0 comments on commit bd97a8f

Please sign in to comment.