From 024469ac0a60ae347d2b7a19cdc06c6abee1c44d Mon Sep 17 00:00:00 2001 From: guille Date: Wed, 2 Mar 2022 12:56:20 -0500 Subject: [PATCH] Link materials and lca_materials in the city --- city_model_structure/city.py | 2 +- .../data_classes/nrel_layer_archetype.py | 12 +++++++++++- imports/construction/nrel_physics_interface.py | 5 +++-- imports/geometry/rhino.py | 2 +- imports/life_cycle_assessment/lca_material.py | 5 +++-- unittests/test_construction_factory.py | 6 ++++-- unittests/test_life_cycle_assessment_factory.py | 6 ++++-- 7 files changed, 27 insertions(+), 11 deletions(-) diff --git a/city_model_structure/city.py b/city_model_structure/city.py index 3e0bb2d4..8145665f 100644 --- a/city_model_structure/city.py +++ b/city_model_structure/city.py @@ -420,7 +420,7 @@ class City: """ self._lca_materials = value - def get_lca_material(self, lca_id) -> LcaMaterial: + def lca_material(self, lca_id) -> LcaMaterial: """ Get the lca materiol matching the given Id :return: LcaMaterial or None diff --git a/imports/construction/data_classes/nrel_layer_archetype.py b/imports/construction/data_classes/nrel_layer_archetype.py index 26b14066..46e0ea64 100644 --- a/imports/construction/data_classes/nrel_layer_archetype.py +++ b/imports/construction/data_classes/nrel_layer_archetype.py @@ -10,7 +10,8 @@ class NrelLayerArchetype: NrelLayerArchetype class """ def __init__(self, name, solar_absorptance, thermal_absorptance, visible_absorptance, thickness=None, - conductivity=None, specific_heat=None, density=None, no_mass=False, thermal_resistance=None): + conductivity=None, specific_heat=None, density=None, no_mass=False, thermal_resistance=None, + lca_id=None): self._thickness = thickness self._conductivity = conductivity self._specific_heat = specific_heat @@ -21,6 +22,7 @@ class NrelLayerArchetype: self._no_mass = no_mass self._name = name self._thermal_resistance = thermal_resistance + self._lca_id = lca_id @property def thickness(self): @@ -101,3 +103,11 @@ class NrelLayerArchetype: :return: float """ return self._thermal_resistance + + @property + def lca_id(self): + """ + Get nrel lca_id equivalent for the material + :return: int + """ + return self._lca_id diff --git a/imports/construction/nrel_physics_interface.py b/imports/construction/nrel_physics_interface.py index 91a76b99..f01297b8 100644 --- a/imports/construction/nrel_physics_interface.py +++ b/imports/construction/nrel_physics_interface.py @@ -71,6 +71,7 @@ class NrelPhysicsInterface: for current_layer in c_lib['layers']['layer']: material_lib = self._search_construction_type('material', current_layer['material']) name = material_lib['@name'] + lca_id = material_lib['@lca_id'] solar_absorptance = material_lib['solar_absorptance']['#text'] thermal_absorptance = material_lib['thermal_absorptance']['#text'] visible_absorptance = material_lib['visible_absorptance']['#text'] @@ -81,7 +82,7 @@ class NrelPhysicsInterface: if units != 'm2 K/W': raise Exception(f'thermal resistance units = {units}, expected m2 K/W') layer = nla(name, solar_absorptance, thermal_absorptance, visible_absorptance, no_mass=no_mass, - thermal_resistance=thermal_resistance) + thermal_resistance=thermal_resistance, lca_id=lca_id) else: thickness = current_layer['thickness']['#text'] units = current_layer['thickness']['@units'] @@ -100,7 +101,7 @@ class NrelPhysicsInterface: if units != 'kg/m3': raise Exception(f'density units = {units}, expected kg/m3') layer = nla(name, solar_absorptance, thermal_absorptance, visible_absorptance, thickness=thickness, - conductivity=conductivity, specific_heat=specific_heat, density=density) + conductivity=conductivity, specific_heat=specific_heat, density=density, lca_id=lca_id) layers.append(layer) thermal_opening = None diff --git a/imports/geometry/rhino.py b/imports/geometry/rhino.py index d8751d25..23df7202 100644 --- a/imports/geometry/rhino.py +++ b/imports/geometry/rhino.py @@ -24,7 +24,7 @@ class Rhino: self._max_x = self._max_y = self._max_z = min_float @staticmethod - def _solid_points(coordinates) -> np.ndarray: + def _solid_points(coordinates): solid_points = np.fromstring(coordinates, dtype=float, sep=' ') solid_points = GeometryHelper.to_points_matrix(solid_points) return solid_points diff --git a/imports/life_cycle_assessment/lca_material.py b/imports/life_cycle_assessment/lca_material.py index ee335a7b..e0081b7c 100644 --- a/imports/life_cycle_assessment/lca_material.py +++ b/imports/life_cycle_assessment/lca_material.py @@ -7,6 +7,7 @@ Contributor Mohammad Reza mohammad.seyedabadi@mail.concordia.ca import xmltodict from pathlib import Path from city_model_structure.building_demand.material import Material +from city_model_structure.lca_material import LcaMaterial as LcaMat class LcaMaterial: @@ -23,7 +24,7 @@ class LcaMaterial: self._lca = xmltodict.parse(xml.read()) for material in self._lca["library"]["building_materials"]['material']: - _lca_material = LcaMaterial() + _lca_material = LcaMat() _lca_material.type = material['@type'] _lca_material.id = material['@id'] _lca_material.name = material['@name'] @@ -35,6 +36,6 @@ class LcaMaterial: _lca_material.onsite_recycling_ratio = material['onsite_recycling_ratio'] _lca_material.company_recycling_ratio = material['company_recycling_ratio'] _lca_material.landfilling_ratio = material['landfilling_ratio'] - _lca_material.cost = material['cost']['#text'] + _lca_material.cost = 10 # todo: change this into material['cost']['#text'] _lca_material._cost_unit = material['cost']['@unit'] self._city.lca_materials.append(_lca_material) diff --git a/unittests/test_construction_factory.py b/unittests/test_construction_factory.py index e9da8012..03266f95 100644 --- a/unittests/test_construction_factory.py +++ b/unittests/test_construction_factory.py @@ -9,7 +9,7 @@ from unittest import TestCase from imports.geometry_factory import GeometryFactory from imports.construction_factory import ConstructionFactory from imports.geometry.helpers.geometry_helper import GeometryHelper - +from imports.life_cycle_assessment_factory import LifeCycleAssessment class TestConstructionFactory(TestCase): """ @@ -28,6 +28,7 @@ class TestConstructionFactory(TestCase): file = 'pluto_building.gml' file_path = (self._example_path / file).resolve() self._city = GeometryFactory('citygml', file_path).city + LifeCycleAssessment('material', self._city).enrich() self.assertIsNotNone(self._city, 'city is none') return self._city @@ -60,7 +61,8 @@ class TestConstructionFactory(TestCase): if thermal_boundary.surface.type != 'Ground': self.assertIsNotNone(thermal_boundary.outside_solar_absorptance, 'outside_solar_absorptance is none') self.assertIsNotNone(thermal_boundary.window_ratio, 'window_ratio is none') - print(thermal_boundary.layers) + for layer in thermal_boundary.layers: + self.assertTrue(city.lca_material(layer.material.lca_id) is not None) def test_city_with_construction_reduced_library(self): """ diff --git a/unittests/test_life_cycle_assessment_factory.py b/unittests/test_life_cycle_assessment_factory.py index f7134f20..9e2e3e62 100644 --- a/unittests/test_life_cycle_assessment_factory.py +++ b/unittests/test_life_cycle_assessment_factory.py @@ -47,8 +47,10 @@ class TestLifeCycleAssessment(TestCase): city_file = "../unittests/tests_data/C40_Final.gml" city = GeometryFactory('citygml', city_file).city LifeCycleAssessment('material', city).enrich() - for material in city.materials: - self.assertTrue(len(city.materials) > 0) + self.assertTrue(len(city.lca_materials) > 0) + for lca_material in city.lca_materials: + lca_mat = city.lca_material(lca_material.id) + self.assertTrue(lca_mat is not None)