add layer generation to trnsys

This commit is contained in:
Guille Gutierrez 2024-01-25 07:59:14 +01:00
parent 6ab8d88173
commit 32ed8671d8
2 changed files with 61 additions and 4 deletions

View File

@ -23,6 +23,8 @@ class Trnsys:
for building in target_buildings:
buildings.append(self._city.city_object(building))
self._buildings = buildings
print("trnsys constructor completed")
self.export()
def _header(self, f, building):
f.write('***************************************\n')
@ -41,7 +43,8 @@ class Trnsys:
f.write(f'* Year build: {building.year_of_construction}\n')
f.write('***************************************\n')
def _properties(self, f):
@staticmethod
def _properties(f):
f.write('***************************************\n')
f.write(f'* Properties\n')
f.write('***************************************\n')
@ -64,6 +67,32 @@ class Trnsys:
f.write('* Daylight parameters\n')
f.write(' UDIMIN=100 : UDIMAX=2000 : DAMIN=300\n')
@staticmethod
def _types(f, building):
f.write('***************************************\n')
f.write(f'* Types\n')
f.write('***************************************\n')
f.write(f'* Layers\n')
f.write('***************************************\n')
layers = {}
for thermal_zone in building.thermal_zones_from_internal_zones:
for thermal_boundary in thermal_zone.thermal_boundaries:
for layer in thermal_boundary.layers:
layers[layer.material_name] = {
'conductivity': layer.conductivity,
'capacity': '1', # todo: ask oriol about this
'density': layer.density,
'pert': '0', # todo: ask oriol about this
'penrt': '0', # todo: ask oriol about this
}
f.write('PROPERTIES\n')
for layer_name, values in layers.items():
f.write(f'LAYER {layer_name.replace(" ", "_").upper()}\n')
for attribute, value in values.items():
f.write(f'{attribute.upper()}=\t{value}\t')
f.write('\n')
@staticmethod
def _geometry_information(f, building):
f.write('[Geometry]\n')
@ -82,7 +111,6 @@ class Trnsys:
f.write(f'Layer {i}: {layer.material_name}\n')
f.write(f'Thickness: {layer.thickness}m\n')
@staticmethod
def _wall_information(f, building):
f.write('[Wall Section]\n')
@ -91,12 +119,17 @@ class Trnsys:
f.write(f'Height: {building.upper_corner[2] - building.lower_corner[2]}\n')
def export(self):
print("export")
for building in self._buildings:
path = Path(self._path / f'{building.name}.b18')
with open(path, 'w', encoding='utf-8') as f:
print(path)
self._header(f, building)
self._properties(f)
Trnsys._properties(f)
Trnsys._types(f, building)
"""
self._building_information(f, building)
Trnsys._geometry_information(f, building)
Trnsys._wall_information(f, building)
"""

View File

@ -147,3 +147,27 @@ class TestExports(TestCase):
EnergyBuildingsExportsFactory('idf', city, self._output_path).export()
except Exception:
self.fail("Idf ExportsFactory raised ExceptionType unexpectedly!")
def test_trnsys_export(self):
"""
export to Trnsys
"""
file = 'test.geojson'
file_path = (self._example_path / file).resolve()
city = GeometryFactory('geojson',
path=file_path,
height_field='citygml_me',
year_of_construction_field='ANNEE_CONS',
function_field='CODE_UTILI',
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
self.assertIsNotNone(city, 'city is none')
EnergyBuildingsExportsFactory('trnsys', city, self._output_path).export()
ConstructionFactory('nrcan', city).enrich()
EnergyBuildingsExportsFactory('idf', city, self._output_path).export()
UsageFactory('nrcan', city).enrich()
WeatherFactory('epw', city).enrich()
try:
EnergyBuildingsExportsFactory('trnsys', city, self._output_path).export()
except Exception:
self.fail("Trnsys ExportsFactory raised ExceptionType unexpectedly!")