Idf surfaces connection

This commit is contained in:
Guille 2020-10-27 13:19:50 -04:00
parent 20d9f00e77
commit e8758eb76d
6 changed files with 167 additions and 50 deletions

View File

@ -25,7 +25,6 @@ class UsageZone:
self._days_year = None self._days_year = None
# todo: this must come from library, talk to Rabeeh # todo: this must come from library, talk to Rabeeh
self._mechanical_air_change = ConfigurationHelper().min_air_change self._mechanical_air_change = ConfigurationHelper().min_air_change
self._occupancy = None self._occupancy = None
self._schedules = None self._schedules = None

View File

@ -782,4 +782,27 @@
<infiltration_rate_for_ventilation_system_off units="ACH">0.10</infiltration_rate_for_ventilation_system_off> <infiltration_rate_for_ventilation_system_off units="ACH">0.10</infiltration_rate_for_ventilation_system_off>
<infiltration_rate_for_ventilation_system_on units="ACH">0</infiltration_rate_for_ventilation_system_on> <infiltration_rate_for_ventilation_system_on units="ACH">0</infiltration_rate_for_ventilation_system_on>
</archetype> </archetype>
<archetype id="35" building_type="residential" reference_standard="ASHRAE 189.1_2009" climate_zone="ASHRAE_2004:4A">
<constructions>
<construction id="15" type="exterior wall" >
<window_ratio units="-">0.3</window_ratio>
<window>3</window>
</construction>
<construction id="12" type="exterior slab">
<window_ratio units="-">0</window_ratio>
<window/>
</construction>
<construction id="9" type="roof" >
<window_ratio units="-">0</window_ratio>
<window/>
</construction>
</constructions>
<average_storey_height units="m">3.05</average_storey_height>
<number_of_storeys units="-">3</number_of_storeys>
<thermal_capacity units="kJ/K m2">90</thermal_capacity>
<extra_loses_due_to_thermal_bridges units="W/K m2">0.05</extra_loses_due_to_thermal_bridges>
<indirect_heated_ratio units="-">0.15</indirect_heated_ratio>
<infiltration_rate_for_ventilation_system_off units="ACH">0.10</infiltration_rate_for_ventilation_system_off>
<infiltration_rate_for_ventilation_system_on units="ACH">0</infiltration_rate_for_ventilation_system_on>
</archetype>
</archetypes> </archetypes>

View File

@ -9,6 +9,10 @@ from pathlib import Path
class IdfHelper: class IdfHelper:
_THERMOSTAT = 'HVACTEMPLATE:THERMOSTAT'
_IDEAL_LOAD_AIR_SYSTEM = 'HVACTEMPLATE:ZONE:IDEALLOADSAIRSYSTEM'
_SURFACE = 'BUILDINGSURFACE:DETAILED'
idf_surfaces = { idf_surfaces = {
'Wall': 'wall', 'Wall': 'wall',
'Ground': 'floor', 'Ground': 'floor',
@ -23,16 +27,23 @@ class IdfHelper:
self._idf = IDF(self._idf_file_path, self._epw_file_path) self._idf = IDF(self._idf_file_path, self._epw_file_path)
self._idf.epw = self._epw_file_path self._idf.epw = self._epw_file_path
def add_zone(self, building_name): def add_heating_system(self, building):
for usage_zone in building.usage_zones:
thermostat_name = f'Thermostat {building.name}'
# todo: this will fail for more than one usage zone
static_thermostat = self._idf.newidfobject(self._THERMOSTAT,
Name=thermostat_name,
Constant_Heating_Setpoint=usage_zone.heating_setpoint,
Constant_Cooling_Setpoint=usage_zone.cooling_setpoint
)
for zone in self._idf.idfobjects['ZONE']:
if zone.Name.find(building.name) != -1:
self._idf.newidfobject(self._IDEAL_LOAD_AIR_SYSTEM,
Zone_Name=zone.Name,
Template_Thermostat_Name=static_thermostat.Name
)
self._idf.newidfobject(key='ZONE', Name=building_name, Ceiling_Height='autocalculate', Volume='autocalculate', def add_heating_system2(self):
Floor_Area='autocalculate', Part_of_Total_Floor_Area='yes', )
self._idf.newidfobject("HVACTEMPLATE:ZONE:IDEALLOADSAIRSYSTEM", Zone_Name=building_name,
Template_Thermostat_Name='', Outdoor_Air_Method="DetailedSpecification", )
def add_heating_system(self):
self._idf.intersect_match()
self._idf.set_default_constructions()
stat = self._idf.newidfobject( stat = self._idf.newidfobject(
"HVACTEMPLATE:THERMOSTAT", "HVACTEMPLATE:THERMOSTAT",
Name="Zone Stat", Name="Zone Stat",
@ -40,9 +51,10 @@ class IdfHelper:
Constant_Cooling_Setpoint=25, Constant_Cooling_Setpoint=25,
) )
for zone in self._idf.idfobjects["ZONE"]: for zone in self._idf.idfobjects["ZONE"]:
self._idf.newidfobject("HVACTEMPLATE:ZONE:IDEALLOADSAIRSYSTEM", self._idf.newidfobject(
"HVACTEMPLATE:ZONE:IDEALLOADSAIRSYSTEM",
Zone_Name=zone.Name, Zone_Name=zone.Name,
Template_Thermostat_Name=stat.Name Template_Thermostat_Name=stat.Name,
) )
@staticmethod @staticmethod
@ -51,7 +63,6 @@ class IdfHelper:
for point in points: for point in points:
point_tuple = (point[0], point[1], point[2]) point_tuple = (point[0], point[1], point[2])
points_list.append(point_tuple) points_list.append(point_tuple)
print(points_list)
return points_list return points_list
@staticmethod @staticmethod
@ -60,46 +71,44 @@ class IdfHelper:
for point in points: for point in points:
point_tuple = (point[0], point[1]) point_tuple = (point[0], point[1])
points_list.append(point_tuple) points_list.append(point_tuple)
points_list.reverse()
return points_list return points_list
def add_block(self, building): def add_block(self, building):
_points = IdfHelper._matrix_to_2d_list(building.foot_print.points) _points = IdfHelper._matrix_to_2d_list(building.foot_print.points)
self._idf.add_block(name=building.name, coordinates=_points, self._idf.add_block(name=building.name, coordinates=_points, height=building.max_height)
height=building.max_height) # self.add_heating_system(building)
def add_surfaces(self, building): def add_surfaces(self, building):
zone = self._idf.newidfobject('ZONE', Name=building.name)
# self.add_heating_system(building)
for surface in building.surfaces: for surface in building.surfaces:
wall = self._idf.newidfobject('BUILDINGSURFACE:DETAILED', Name=surface.name, idf_surface = self.idf_surfaces[surface.type]
Surface_Type=self.idf_surfaces[surface.type], Zone_Name=building.name) wall = self._idf.newidfobject(self._SURFACE, Name=surface.name, Surface_Type=idf_surface, Zone_Name=building.name)
wall.setcoords(IdfHelper._matrix_to_list(surface.points)) wall.setcoords(IdfHelper._matrix_to_list(surface.points))
def run(self, window_ratio=0.35, display_render=False, output_directory='tests'): def run(self, window_ratio=0.35, display_render=False, output_prefix=None, output_directory='tests'):
self._idf.intersect_match() self._idf.intersect_match()
self._idf.set_wwr(window_ratio, construction="Project External Window")
self._idf.set_default_constructions() self._idf.set_default_constructions()
self._idf.set_wwr(window_ratio, construction="Project External Window")
self._idf.translate_to_origin() self._idf.translate_to_origin()
if display_render: if display_render:
self._idf.view_model() self._idf.view_model()
# else: else:
# self._idf.to_obj('ep_outputs/city.obj') self._idf.to_obj('ep_outputs/city.obj')
# Run # Run
self._idf.newidfobject("OUTPUT:METER", Key_Name="Heating:DistrictHeating", Reporting_Frequency="hourly") # self._idf.newidfobject("OUTPUT:METER", Key_Name="Heating:DistrictHeating", Reporting_Frequency="hourly")
self._idf.newidfobject("OUTPUT:METER", Key_Name="Cooling:DistrictCooling", Reporting_Frequency="hourly" ) # self._idf.newidfobject("OUTPUT:METER", Key_Name="Cooling:DistrictCooling", Reporting_Frequency="hourly")
print('**************************************************') self._idf.run(output_prefix=output_prefix, output_directory=output_directory)
self._idf.run(output_directory=output_directory)
@staticmethod @staticmethod
def read_eso(eso_path): def read_eso(eso_path):
print('**************************************************') print("read_eso")
dd, data = esoreader.read(str(eso_path)) return [], []
"""
print(data) eso = esoreader.read(str(eso_path))
list_values = [v for v in df.values()]
list_values = [v for v in data.values()]
heating = [(float(x)) / 3600000.0 for x in list_values[0]] heating = [(float(x)) / 3600000.0 for x in list_values[0]]
cooling = [(float(x)) / 3600000.0 for x in list_values[1]] cooling = [(float(x)) / 3600000.0 for x in list_values[1]]
print(heating)
print(cooling)
return heating, cooling
return heating, cooling
"""

View File

@ -5,9 +5,12 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc
""" """
from pathlib import Path from pathlib import Path
from unittest import TestCase from unittest import TestCase
from geomeppy import IDF
from geometry.geometry_factory import GeometryFactory from geometry.geometry_factory import GeometryFactory
from physics.physics_factory import PhysicsFactory
from usage.usage_factory import UsageFactory
from helpers.idf_helper import IdfHelper from helpers.idf_helper import IdfHelper
from geomeppy import IDF
from esoreader import EsoFile
class TestIdf(TestCase): class TestIdf(TestCase):
@ -23,27 +26,87 @@ class TestIdf(TestCase):
self._city_gml = None self._city_gml = None
self._example_path = (Path(__file__).parent.parent / 'tests_data').resolve() self._example_path = (Path(__file__).parent.parent / 'tests_data').resolve()
def _get_citygml(self): def _get_city(self):
if self._city_gml is None: if self._city_gml is None:
file_path = (self._example_path / 'buildings.gml').resolve() file_path = (self._example_path / 'buildings.gml').resolve()
self._city_gml = GeometryFactory('citygml', file_path).city self._city_gml = GeometryFactory('citygml', file_path).city
self.assertIsNotNone(self._city_gml, 'city is none') PhysicsFactory('us_new_york', self._city_gml, base_path=self._example_path)
UsageFactory('us_new_york', self._city_gml)
return self._city_gml return self._city_gml
def test_idf_run(self): def test_idf_blocks(self):
idd_file_path = (self._example_path / 'energy+.idd').resolve() idd_file_path = (self._example_path / 'energy+.idd').resolve()
idf_file_path = (self._example_path / 'minimal.idf').resolve() idf_file_path = (self._example_path / 'minimal.idf').resolve()
epw_file_path = (self._example_path / 'montreal.epw').resolve() epw_file_path = (self._example_path / 'montreal.epw').resolve()
_idf = IdfHelper(idf_file_path, idd_file_path, epw_file_path) _idf = IdfHelper(idf_file_path, idd_file_path, epw_file_path)
city = self._get_citygml() city = self._get_city()
for building in city.buildings: for building in city.buildings:
_idf.add_block(building) _idf.add_block(building)
_idf.run(output_prefix='test_idf_blocks', output_directory="ep_outputs")
heating, cooling = IdfHelper.read_eso((Path(__file__).parent / 'ep_outputs/eplusout.eso'))
self.assertEqual(len(heating), 0)
# _idf.add_surfaces(building) def test_idf_surfaces(self):
# for surface in building.surfaces: idd_file_path = (self._example_path / 'energy+.idd').resolve()
# _idf.add_surface(surface, building.name) idf_file_path = (self._example_path / 'minimal.idf').resolve()
epw_file_path = (self._example_path / 'montreal.epw').resolve()
_idf = IdfHelper(idf_file_path, idd_file_path, epw_file_path)
city = self._get_city()
for building in city.buildings:
_idf.add_surfaces(building)
_idf.run(output_prefix='test_idf_surfaces', output_directory="ep_outputs")
heating, cooling = IdfHelper.read_eso((Path(__file__).parent / 'ep_outputs/eplusout.eso'))
self.assertEqual(1, 1, "arent equal")
_idf.run(output_directory="ep_outputs") def test_tutorial_2(self):
IdfHelper.read_eso((Path(__file__).parent / 'ep_outputs/eplusout.eso')) idd_file_path = (self._example_path / 'energy+.idd').resolve()
self.assertTrue(True) idf_file_path = (self._example_path / 'minimal.idf').resolve()
epw_file_path = (self._example_path / 'montreal.epw').resolve()
IDF.setiddname(str(idd_file_path), testing=True)
idf = IDF(str(idf_file_path))
idf.epw = str(epw_file_path)
idf.add_block(
name="Two storey",
coordinates=[(10, 0), (10, 5), (0, 5), (0, 0)],
height=6,
num_stories=2,
)
idf.add_block(
name="One storey", coordinates=[(10, 5), (10, 10), (0, 10), (0, 5)], height=3
)
idf.intersect_match()
idf.set_default_constructions()
# add a heating system
stat = idf.newidfobject(
"HVACTEMPLATE:THERMOSTAT",
Name="Zone Stat",
Constant_Heating_Setpoint=20,
Constant_Cooling_Setpoint=25,
)
for zone in idf.idfobjects["ZONE"]:
idf.newidfobject(
"HVACTEMPLATE:ZONE:IDEALLOADSAIRSYSTEM",
Zone_Name=zone.Name,
Template_Thermostat_Name=stat.Name,
)
# add some output variables
idf.newidfobject(
"OUTPUT:VARIABLE",
Variable_Name="Zone Ideal Loads Supply Air Total Heating Energy",
Reporting_Frequency="Hourly",
)
idf.newidfobject(
"OUTPUT:VARIABLE",
Variable_Name="Zone Ideal Loads Supply Air Total Cooling Energy",
Reporting_Frequency="Hourly",
)
# run a set of simulations, moving glazing from mostly on the South facade, to mostly on the North facade
north_wwr = [i / 10 for i in range(1, 10)]
south_wwr = [1 - wwr for wwr in north_wwr]
idf.run(
output_directory="ep_outputs",
expandobjects=True,
verbose="v",
)
results = []

View File

@ -45,4 +45,5 @@ class TestOccupancyFactory(TestCase):
city = self._get_citygml_with_usage() city = self._get_citygml_with_usage()
OccupancyFactory('demo', city) OccupancyFactory('demo', city)
for building in city.buildings: for building in city.buildings:
self.assertTrue(building.usage_zones[0].schedules) for usage_zone in building.usage_zones:
self.assertTrue(usage_zone.schedules)

View File

@ -782,5 +782,27 @@
<infiltration_rate_for_ventilation_system_off units="ACH">0.10</infiltration_rate_for_ventilation_system_off> <infiltration_rate_for_ventilation_system_off units="ACH">0.10</infiltration_rate_for_ventilation_system_off>
<infiltration_rate_for_ventilation_system_on units="ACH">0</infiltration_rate_for_ventilation_system_on> <infiltration_rate_for_ventilation_system_on units="ACH">0</infiltration_rate_for_ventilation_system_on>
</archetype> </archetype>
<archetype id="35" building_type="residential" reference_standard="ASHRAE 189.1_2009" climate_zone="ASHRAE_2004:4A">
<constructions>
<construction id="15" type="exterior wall" >
<window_ratio units="-">0.3</window_ratio>
<window>3</window>
</construction>
<construction id="12" type="exterior slab">
<window_ratio units="-">0</window_ratio>
<window/>
</construction>
<construction id="9" type="roof" >
<window_ratio units="-">0</window_ratio>
<window/>
</construction>
</constructions>
<average_storey_height units="m">3.05</average_storey_height>
<number_of_storeys units="-">3</number_of_storeys>
<thermal_capacity units="kJ/K m2">90</thermal_capacity>
<extra_loses_due_to_thermal_bridges units="W/K m2">0.05</extra_loses_due_to_thermal_bridges>
<indirect_heated_ratio units="-">0.15</indirect_heated_ratio>
<infiltration_rate_for_ventilation_system_off units="ACH">0.10</infiltration_rate_for_ventilation_system_off>
<infiltration_rate_for_ventilation_system_on units="ACH">0</infiltration_rate_for_ventilation_system_on>
</archetype>
</archetypes> </archetypes>