def window_material_by_name(material_name): """Get an window material from the library given the material name. Args: material_name: A text string for the name of the material. """ try: # see if the material has already been loaded to a Python object return _idf_window_materials[material_name] except KeyError: # material likely needs to be loaded from standards data try: _mat_dict = _window_standards_dict[material_name] except KeyError: # material is nowhere to be found; raise an error raise ValueError( '"{}" was not found in the window energy material library.'. format(material_name)) # create the Python object from the standards gem dictionary if _mat_dict['material_type'] == 'StandardGlazing': _mat_obj = EnergyWindowMaterialGlazing.from_standards_dict(_mat_dict) elif _mat_dict['material_type'] == 'SimpleGlazing': _mat_obj = EnergyWindowMaterialSimpleGlazSys.from_standards_dict( _mat_dict) elif _mat_dict['material_type'] == 'Gas': _mat_obj = EnergyWindowMaterialGas.from_standards_dict(_mat_dict) else: raise ValueError( 'Standards gem material type "{}" is not recognized.'.format( _mat_dict['material_type'])) _mat_obj.lock() _idf_window_materials[ material_name] = _mat_obj # next time, it will be loaded faster return _mat_obj
def test_gas_to_from_standards_dict(): """Test initialization of EnergyWindowMaterialGas objects from standards gem.""" standards_dict = { "name": "AIR 13MM", "material_type": "Gas", "thickness": 0.5, "gas_type": "Air" } mat_1 = EnergyWindowMaterialGas.from_standards_dict(standards_dict) assert mat_1.name == 'AIR 13MM' assert mat_1.thickness == pytest.approx(0.0127, rel=1e-2) assert mat_1.gas_type == 'Air'