def opaque_material_by_name(material_name):
    """Get an opaque 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_opaque_materials[material_name]
    except KeyError:  # material likely needs to be loaded from standards data
        try:
            _mat_dict = _opaque_standards_dict[material_name]
        except KeyError:  # material is nowhere to be found; raise an error
            raise ValueError(
                '"{}" was not found in the opaque energy material library.'.
                format(material_name))

    # create the Python object from the standards gem dictionary
    if _mat_dict['material_type'] == 'StandardOpaqueMaterial':
        _mat_obj = EnergyMaterial.from_standards_dict(_mat_dict)
    elif _mat_dict['material_type'] in ('MasslessOpaqueMaterial', 'AirGap'):
        _mat_obj = EnergyMaterialNoMass.from_standards_dict(_mat_dict)
    else:
        raise ValueError(
            'Standards gem material type "{}" is not recognized.'.format(
                _mat_dict['material_type']))
    _mat_obj.lock()
    _idf_opaque_materials[
        material_name] = _mat_obj  # next time, it will be loaded faster
    return _mat_obj
Esempio n. 2
0
def test_material_to_from_standards_dict():
    """Test the initialization of EnergyMaterial objects from standards gem."""
    standards_dict = {
        "name": "Extruded Polystyrene - XPS - 6 in. R30.00",
        "material_type": "StandardOpaqueMaterial",
        "roughness": "MediumSmooth",
        "thickness": 6.0,
        "conductivity": 0.20,
        "resistance": 29.9999994,
        "density": 1.3,
        "specific_heat": 0.35,
        "thermal_absorptance": None,
        "solar_absorptance": None,
        "visible_absorptance": None
    }
    mat_1 = EnergyMaterial.from_standards_dict(standards_dict)

    assert mat_1.name == 'Extruded Polystyrene - XPS - 6 in. R30.00'
    assert mat_1.thickness == pytest.approx(0.1524, rel=1e-3)
    assert mat_1.conductivity == pytest.approx(0.028826, rel=1e-3)
    assert mat_1.density == pytest.approx(20.82, rel=1e-3)
    assert mat_1.specific_heat == pytest.approx(1464.435, rel=1e-3)
    assert mat_1.roughness == 'MediumSmooth'
    assert mat_1.resistivity == pytest.approx(1 / 0.028826, rel=1e-3)