示例#1
0
def from_rooms_radial(model_file, grid_size, offset, include_mesh, keep_out,
                      wall_offset, dir_count, start_vector, mesh_radius, room,
                      write_json, folder, output_file):
    """Generate SensorGrids of radial directions around positions from room floors.

    \b
    Args:
        model_file: Full path to a HBJSON or HBPkl Model file.
    """
    try:
        # re-serialize the Model and extract rooms and units
        model = Model.from_file(model_file)
        rooms = model.rooms if room is None or len(room) == 0 else \
            [r for r in model.rooms if r.identifier in room]
        grid_size = parse_distance_string(grid_size, model.units)
        offset = parse_distance_string(offset, model.units)
        wall_offset = parse_distance_string(wall_offset, model.units)
        vec = [float(v) for v in start_vector.split()]
        st_vec = Vector3D(*vec)

        # loop through the rooms and generate sensor grids
        sensor_grids = []
        remove_out = not keep_out
        for room in rooms:
            sg = room.properties.radiance.generate_sensor_grid_radial(
                grid_size,
                offset=offset,
                remove_out=remove_out,
                wall_offset=wall_offset,
                dir_count=dir_count,
                start_vector=st_vec,
                mesh_radius=mesh_radius)
            if sg is not None:
                sensor_grids.append(sg)
        if not include_mesh:
            for sg in sensor_grids:
                sg.mesh = None

        # write the sensor grids to the output file or folder
        if folder is None:
            if write_json:
                output_file.write(
                    json.dumps([sg.to_dict() for sg in sensor_grids]))
            else:
                output_file.write('\n'.join(
                    [sg.to_radiance() for sg in sensor_grids]))
        else:
            if write_json:
                for sg in sensor_grids:
                    sg.to_json(folder)
            else:
                for sg in sensor_grids:
                    sg.to_file(folder)
    except Exception as e:
        _logger.exception('Grid generation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
示例#2
0
def test_check_duplicate_face_identifiers():
    """Test the check_duplicate_face_identifiers method."""
    pts_1 = [
        Point3D(0, 0, 0),
        Point3D(0, 10, 0),
        Point3D(10, 10, 0),
        Point3D(10, 0, 0)
    ]
    pts_2 = [
        Point3D(0, 0, 0),
        Point3D(0, 0, 3),
        Point3D(0, 10, 3),
        Point3D(0, 10, 0)
    ]
    pts_3 = [
        Point3D(0, 0, 0),
        Point3D(10, 0, 0),
        Point3D(10, 0, 3),
        Point3D(0, 0, 3)
    ]
    pts_4 = [
        Point3D(10, 10, 0),
        Point3D(0, 10, 0),
        Point3D(0, 10, 3),
        Point3D(10, 10, 3)
    ]
    pts_5 = [
        Point3D(10, 10, 0),
        Point3D(10, 0, 0),
        Point3D(10, 0, 3),
        Point3D(10, 10, 3)
    ]
    pts_6 = [
        Point3D(10, 0, 3),
        Point3D(10, 10, 3),
        Point3D(0, 10, 3),
        Point3D(0, 0, 3)
    ]
    face_1 = Face('Face1', Face3D(pts_1))
    face_2 = Face('Face2', Face3D(pts_2))
    face_3 = Face('Face3', Face3D(pts_3))
    face_4 = Face('Face4', Face3D(pts_4))
    face_5 = Face('Face5', Face3D(pts_5))
    face_6 = Face('Face6', Face3D(pts_6))
    face_7 = Face('Face1', Face3D(pts_6))
    room_1 = Room('TestRoom', [face_1, face_2, face_3, face_4, face_5, face_6])
    room_2 = Room('TestRoom', [face_1, face_2, face_3, face_4, face_5, face_7])

    model_1 = Model('TestHouse', [room_1])
    model_2 = Model('TestHouse', [room_2])

    assert model_1.check_duplicate_face_identifiers(False)
    assert not model_2.check_duplicate_face_identifiers(False)
    with pytest.raises(ValueError):
        model_2.check_duplicate_face_identifiers(True)
示例#3
0
def test_to_dict():
    """Test the Model to_dict method."""
    room = Room.from_box('TinyHouseZone', 5, 10, 3)
    south_face = room[3]
    south_face.apertures_by_ratio(0.4, 0.01)
    south_face.apertures[0].overhang(0.5, indoor=False)
    south_face.apertures[0].overhang(0.5, indoor=True)
    south_face.apertures[0].move_shades(Vector3D(0, 0, -0.5))
    north_face = room[1]
    door_verts = [
        Point3D(2, 10, 0.1),
        Point3D(1, 10, 0.1),
        Point3D(1, 10, 2.5),
        Point3D(2, 10, 2.5)
    ]
    aperture_verts = [
        Point3D(4.5, 10, 1),
        Point3D(2.5, 10, 1),
        Point3D(2.5, 10, 2.5),
        Point3D(4.5, 10, 2.5)
    ]
    door = Door('FrontDoor', Face3D(door_verts))
    north_face.add_door(door)
    aperture = Aperture('FrontAperture', Face3D(aperture_verts))
    north_face.add_aperture(aperture)
    model = Model('TinyHouse', [room])

    model_dict = model.to_dict()
    assert model_dict['type'] == 'Model'
    assert model_dict['identifier'] == 'TinyHouse'
    assert model_dict['display_name'] == 'TinyHouse'
    assert 'rooms' in model_dict
    assert len(model_dict['rooms']) == 1
    assert 'faces' in model_dict['rooms'][0]
    assert len(model_dict['rooms'][0]['faces']) == 6
    assert 'apertures' in model_dict['rooms'][0]['faces'][3]
    assert len(model_dict['rooms'][0]['faces'][3]['apertures']) == 1
    assert 'doors' in model_dict['rooms'][0]['faces'][1]
    assert len(model_dict['rooms'][0]['faces'][1]['doors']) == 1
    assert 'outdoor_shades' in model_dict['rooms'][0]['faces'][3]['apertures'][
        0]
    assert len(model_dict['rooms'][0]['faces'][3]['apertures'][0]
               ['outdoor_shades']) == 1
    assert 'properties' in model_dict
    assert model_dict['properties']['type'] == 'ModelProperties'
示例#4
0
def test_apertures_by_identifier():
    """Test the apertures_by_identifier method."""
    room = Room.from_box('TinyHouseZone', 5, 10, 3)
    south_face = room[3]
    south_face.apertures_by_ratio(0.4, 0.01)
    model = Model('TinyHouse', [room])

    assert len(model.apertures_by_identifier(['TinyHouseZone_Back_Glz0'])) == 1
    with pytest.raises(ValueError):
        model.apertures_by_identifier(['NotAnAperture'])

    model.remove_assigned_apertures()
    with pytest.raises(ValueError):
        model.shades_by_identifier(['TinyHouseZone_Back_Glz0'])
示例#5
0
def test_to_dict_multizone_house():
    """Test the Model to_dict method with a multi-zone house."""
    first_floor = Room.from_box('First_Floor', 10, 10, 3, origin=Point3D(0, 0, 0))
    second_floor = Room.from_box('Second_Floor', 10, 10, 3, origin=Point3D(0, 0, 3))
    for face in first_floor[1:5]:
        face.apertures_by_ratio(0.2, 0.01)
    for face in second_floor[1:5]:
        face.apertures_by_ratio(0.2, 0.01)

    pts_1 = [Point3D(0, 0, 6), Point3D(0, 10, 6), Point3D(10, 10, 6), Point3D(10, 0, 6)]
    pts_2 = [Point3D(0, 0, 6), Point3D(5, 0, 9), Point3D(5, 10, 9), Point3D(0, 10, 6)]
    pts_3 = [Point3D(10, 0, 6), Point3D(10, 10, 6), Point3D(5, 10, 9), Point3D(5, 0, 9)]
    pts_4 = [Point3D(0, 0, 6), Point3D(10, 0, 6), Point3D(5, 0, 9)]
    pts_5 = [Point3D(10, 10, 6), Point3D(0, 10, 6), Point3D(5, 10, 9)]
    face_1 = Face('AtticFace1', Face3D(pts_1))
    face_2 = Face('AtticFace2', Face3D(pts_2))
    face_3 = Face('AtticFace3', Face3D(pts_3))
    face_4 = Face('AtticFace4', Face3D(pts_4))
    face_5 = Face('AtticFace5', Face3D(pts_5))
    attic = Room('Attic', [face_1, face_2, face_3, face_4, face_5], 0.01, 1)

    mod_set = ModifierSet('Attic_Construction_Set')
    mod_set.floor_set.interior_modifier = Plastic('AtticFloor', 0.4)
    mod_set.roof_ceiling_set.exterior_modifier = Plastic('AtticRoof', 0.6)
    attic.properties.radiance.modifier_set = mod_set

    Room.solve_adjacency([first_floor, second_floor, attic], 0.01)

    model = Model('Multi_Zone_Single_Family_House', [first_floor, second_floor, attic])
    model_dict = model.to_dict()

    assert 'radiance' in model_dict['properties']
    assert 'modifiers' in model_dict['properties']['radiance']
    assert 'modifier_sets' in model_dict['properties']['radiance']

    assert len(model_dict['properties']['radiance']['modifiers']) == 2
    assert len(model_dict['properties']['radiance']['modifier_sets']) == 1

    assert model_dict['rooms'][0]['faces'][5]['boundary_condition']['type'] == 'Surface'
    assert model_dict['rooms'][1]['faces'][0]['boundary_condition']['type'] == 'Surface'
    assert model_dict['rooms'][1]['faces'][5]['boundary_condition']['type'] == 'Surface'
    assert model_dict['rooms'][2]['faces'][0]['boundary_condition']['type'] == 'Surface'

    assert model_dict['rooms'][2]['properties']['radiance']['modifier_set'] == \
        mod_set.identifier
示例#6
0
def test_afn_plenum_zone():
    """Test case where no infiltration load exists."""
    zone_pts = Face3D(
        [Point3D(0, 0),
         Point3D(20, 0),
         Point3D(20, 10),
         Point3D(0, 10)])
    room = Room.from_polyface3d('PlenumRoom',
                                Polyface3D.from_offset_face(zone_pts, 1))
    room.properties.energy.program_type = prog_type_lib.plenum_program

    # Make model
    model = Model('PlenumSimple', [room])

    # generate afn, w/ average leakage
    afn.generate(model.rooms,
                 leakage_type='Medium',
                 use_room_infiltration=True)
    faces = model.faces

    # check ext wall
    crack = faces[1].properties.energy.vent_crack
    chk_cof = CRACK_TEMPLATE_DATA['external_medium_cracks']['wall_flow_cof']
    chk_exp = CRACK_TEMPLATE_DATA['external_medium_cracks']['wall_flow_exp']
    assert crack.flow_coefficient == pytest.approx(chk_cof * faces[1].area,
                                                   abs=1e-10)
    assert crack.flow_exponent == pytest.approx(chk_exp, abs=1e-10)

    # check roof
    crack = faces[5].properties.energy.vent_crack
    chk_cof = CRACK_TEMPLATE_DATA['external_medium_cracks']['roof_flow_cof']
    chk_exp = CRACK_TEMPLATE_DATA['external_medium_cracks']['roof_flow_exp']
    assert crack.flow_coefficient == pytest.approx(chk_cof * faces[5].area,
                                                   abs=1e-10)
    assert crack.flow_exponent == pytest.approx(chk_exp, abs=1e-10)

    # generate afn, w/ tight leakage
    afn.generate(model.rooms,
                 leakage_type='Excellent',
                 use_room_infiltration=False)
    faces = model.faces

    # check ext wall
    crack = faces[1].properties.energy.vent_crack
    chk_cof = CRACK_TEMPLATE_DATA['external_excellent_cracks']['wall_flow_cof']
    chk_exp = CRACK_TEMPLATE_DATA['external_excellent_cracks']['wall_flow_exp']
    assert crack.flow_coefficient == pytest.approx(chk_cof * faces[1].area,
                                                   abs=1e-10)
    assert crack.flow_exponent == pytest.approx(chk_exp, abs=1e-10)

    # check roof
    crack = faces[5].properties.energy.vent_crack
    chk_cof = CRACK_TEMPLATE_DATA['external_excellent_cracks']['roof_flow_cof']
    chk_exp = CRACK_TEMPLATE_DATA['external_excellent_cracks']['roof_flow_exp']
    assert crack.flow_coefficient == pytest.approx(chk_cof * faces[5].area,
                                                   abs=1e-10)
    assert crack.flow_exponent == pytest.approx(chk_exp, abs=1e-10)
示例#7
0
def test_add_room_sensors():
    runner = CliRunner()
    input_hb_model = './tests/assets/model/model_radiance_dynamic_states.hbjson'

    result = runner.invoke(add_room_sensors, [input_hb_model])
    assert result.exit_code == 0
    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert len(new_model.properties.radiance.sensor_grids) == 2
示例#8
0
def test_model_add_prefix():
    """Test the model add_prefix method."""
    room = Room.from_box('ShoeBoxZone', 5, 10, 3)
    south_face = room[3]
    south_face.apertures_by_ratio(0.5, 0.01)
    table_geo = Face3D.from_rectangle(2, 2, Plane(o=Point3D(1.5, 4, 1)))
    room.add_indoor_shade(Shade('Table', table_geo))
    prefix = 'New'
    model = Model('ShoeBox', [room])
    model.add_prefix(prefix)

    assert room.identifier.startswith(prefix)
    for face in room.faces:
        assert face.identifier.startswith(prefix)
        for ap in face.apertures:
            assert ap.identifier.startswith(prefix)
    for shd in room.shades:
        assert shd.identifier.startswith(prefix)
示例#9
0
def test_shoe_box_simple():
    runner = CliRunner()
    result = runner.invoke(shoe_box, ['5', '10', '3.5'])
    assert result.exit_code == 0

    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert len(new_model.rooms) == 1
    assert len(new_model.apertures) == 0
示例#10
0
def test_model_from_idf():
    runner = CliRunner()
    input_idf_model = os.path.abspath('./tests/idf/test_shoe_box.idf')

    result = runner.invoke(model_from_idf, [input_idf_model])
    assert result.exit_code == 0
    result_dict = json.loads(result.output)
    model = Model.from_dict(result_dict)
    assert isinstance(model, Model)
示例#11
0
def test_convert_units():
    input_model = './tests/json/single_family_home.hbjson'
    runner = CliRunner()
    result = runner.invoke(convert_units, [input_model, 'Feet'])
    assert result.exit_code == 0

    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert new_model.units == 'Feet'
示例#12
0
def model_occ_schedules(model_json, threshold, period, output_file):
    """Translate a Model's occupancy schedules into a JSON of 0/1 values.

    \b
    Args:
        model_json: Full path to a Model JSON file.
    """
    try:
        # re-serialize the Model
        with open(model_json) as json_file:
            data = json.load(json_file)
        model = Model.from_dict(data)

        # loop through the rooms and collect all unique occupancy schedules
        scheds, room_occupancy = [], {}
        for room in model.rooms:
            people = room.properties.energy.people
            if people is not None:
                model.properties.energy._check_and_add_schedule(
                    people.occupancy_schedule, scheds)
                room_occupancy[room.identifier] = people.occupancy_schedule.identifier
            else:
                room_occupancy[room.identifier] = None

        # process the run period if it is supplied
        if period is not None and period != '' and period != 'None':
            a_per = AnalysisPeriod.from_string(period)
            start = Date(a_per.st_month, a_per.st_day)
            end = Date(a_per.end_month, a_per.end_day)
            a_period = AnalysisPeriod(start.month, start.day, 0, end.month, end.day, 23)
            timestep = a_per.timestep
        else:
            a_per = a_period = AnalysisPeriod()
            start, end, timestep = Date(1, 1), Date(12, 31), 1

        # convert occupancy schedules to lists of 0/1 values
        schedules = {}
        for sch in scheds:
            values = []
            for val in sch.values(timestep, start, end):
                is_occ = 0 if val < threshold else 1
                values.append(is_occ)
            header = Header(Fraction(), 'fraction', a_period)
            schedules[sch.identifier] = HourlyContinuousCollection(header, values)
        if a_per.st_hour != 0 or a_per.end_hour != 23:
            schedules = {key: data.filter_by_analysis_period(a_per)
                         for key, data in schedules.items()}
        schedules = {key: data.values for key, data in schedules.items()}

        # write out the JSON file
        occ_dict = {'schedules': schedules, 'room_occupancy': room_occupancy}
        output_file.write(json.dumps(occ_dict))
    except Exception as e:
        _logger.exception('Model translation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
示例#13
0
def test_remove_ecms():
    runner = CliRunner()
    input_hb_model = './tests/json/ShoeBox.json'

    result = runner.invoke(remove_ecms, [input_hb_model])
    assert result.exit_code == 0
    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert new_model.rooms[0].properties.energy.window_vent_control is None
示例#14
0
def test_model_to_dict_with_program_type():
    """Test Model.to_dict() with standards ProgramTypes."""
    pat_room_program = prog_type_lib.program_type_by_identifier(
        '2013::Hospital::ICU_PatRm')
    room = Room.from_box('Hospital_Patient_Room', 5, 10, 3)
    room.properties.energy.program_type = pat_room_program

    room.properties.energy.add_default_ideal_air()
    ideal_air = room.properties.energy.hvac.duplicate()
    ideal_air.economizer_type = 'DifferentialEnthalpy'
    ideal_air.sensible_heat_recovery = 0.81
    ideal_air.latent_heat_recovery = 0.68
    room.properties.energy.hvac = ideal_air

    pat_rm_setpoint = room.properties.energy.setpoint.duplicate()
    pat_rm_setpoint.identifier = 'Humidity Controlled PatRm Setpt'
    pat_rm_setpoint.heating_setpoint = 21
    pat_rm_setpoint.cooling_setpoint = 24
    pat_rm_setpoint.humidifying_setpoint = 30
    pat_rm_setpoint.dehumidifying_setpoint = 55
    room.properties.energy.setpoint = pat_rm_setpoint

    south_face = room[3]
    south_face.apertures_by_ratio(0.4, 0.01)
    south_face.apertures[0].overhang(0.5, indoor=False)
    south_face.move_shades(Vector3D(0, 0, -0.5))

    room[0].boundary_condition = boundary_conditions.adiabatic
    room[1].boundary_condition = boundary_conditions.adiabatic
    room[2].boundary_condition = boundary_conditions.adiabatic
    room[4].boundary_condition = boundary_conditions.adiabatic
    room[5].boundary_condition = boundary_conditions.adiabatic

    model = Model('Patient_Room_Test_Box', [room])
    model_dict = model.to_dict()

    assert model_dict['properties']['energy']['program_types'][0]['identifier'] == \
        '2013::Hospital::ICU_PatRm'
    assert model_dict['rooms'][0]['properties']['energy']['program_type'] == \
        '2013::Hospital::ICU_PatRm'
    assert 'setpoint' in model_dict['rooms'][0]['properties']['energy']
    assert model_dict['rooms'][0]['properties']['energy']['setpoint']['identifier'] == \
        'Humidity Controlled PatRm Setpt'
    assert 'hvac' in model_dict['rooms'][0]['properties']['energy']
示例#15
0
def test_check_duplicate_room_names():
    """Test the check_duplicate_room_names method."""
    room_south = Room.from_box('Zone1', 5, 5, 3, origin=Point3D(0, 0, 0))
    room_north = Room.from_box('Zone1', 5, 5, 3, origin=Point3D(0, 5, 0))
    room_south[3].apertures_by_ratio(0.4, 0.01)
    Room.solve_adjacency([room_south, room_north], 0.01)

    model_1 = Model('South House', [room_south])
    model_2 = Model('North House', [room_north])

    assert model_1.check_duplicate_room_names(False)
    model_1.add_model(model_2)
    assert not model_1.check_duplicate_room_names(False)
    with pytest.raises(ValueError):
        model_1.check_duplicate_room_names(True)
示例#16
0
def test_lighting_2004():
    runner = CliRunner()
    input_hb_model = './tests/json/ShoeBox.json'

    result = runner.invoke(lighting_2004, [input_hb_model])
    assert result.exit_code == 0
    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert new_model.rooms[0].properties.energy.lighting.watts_per_area == \
        pytest.approx(11.84029, rel=1e-1)
示例#17
0
def test_move():
    """Test the Model move method."""
    room = Room.from_box('Tiny House Zone', 5, 10, 3)
    south_face = room[3]
    south_face.apertures_by_ratio(0.4, 0.01)
    south_face.apertures[0].overhang(0.5, indoor=False)
    south_face.apertures[0].overhang(0.5, indoor=True)
    south_face.apertures[0].move_shades(Vector3D(0, 0, -0.5))
    north_face = room[1]
    door_verts = [Point3D(2, 10, 0.1), Point3D(1, 10, 0.1),
                  Point3D(1, 10, 2.5), Point3D(2, 10, 2.5)]
    aperture_verts = [Point3D(4.5, 10, 1), Point3D(2.5, 10, 1),
                      Point3D(2.5, 10, 2.5), Point3D(4.5, 10, 2.5)]
    door = Door('Front Door', Face3D(door_verts))
    north_face.add_door(door)
    aperture = Aperture('Front Aperture', Face3D(aperture_verts))
    north_face.add_aperture(aperture)

    new_room = room.duplicate()
    model = Model('Tiny House', [new_room])

    vec_1 = Vector3D(2, 2, 0)
    model.move(vec_1)

    assert room.center == \
        model.rooms[0].center.move(Vector3D(-2, -2, 0))
    assert south_face.apertures[0].indoor_shades[0].center == \
        model.rooms[0][3].apertures[0].indoor_shades[0].center.move(Vector3D(-2, -2, 0))
    assert south_face.apertures[0].outdoor_shades[0].center == \
        model.rooms[0][3].apertures[0].outdoor_shades[0].center.move(Vector3D(-2, -2, 0))
    assert room[3].apertures[0].center == \
        model.rooms[0][3].apertures[0].center.move(Vector3D(-2, -2, 0))
    assert room[1].doors[0].center == \
        model.rooms[0][1].doors[0].center.move(Vector3D(-2, -2, 0))

    assert room.floor_area == model.rooms[0].floor_area
    assert room.volume == model.rooms[0].volume
    assert south_face.apertures[0].indoor_shades[0].area == \
        model.rooms[0][3].apertures[0].indoor_shades[0].area
    assert south_face.apertures[0].outdoor_shades[0].area == \
        model.rooms[0][3].apertures[0].outdoor_shades[0].area
    assert room[3].apertures[0].area == model.rooms[0][3].apertures[0].area
    assert room[1].doors[0].area == model.rooms[0][1].doors[0].area
示例#18
0
def test_extruded_border():
    input_model = './tests/json/single_family_home.hbjson'
    runner = CliRunner()
    in_args = [input_model, '0.2', '-i']
    result = runner.invoke(extruded_border, in_args)
    assert result.exit_code == 0

    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert all(len(ap.indoor_shades) > 1 for ap in new_model.apertures)
示例#19
0
def test_windows_by_ratio():
    input_model = './tests/json/single_family_home.hbjson'
    runner = CliRunner()
    result = runner.invoke(windows_by_ratio, [input_model, '0.6'])
    assert result.exit_code == 0

    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert new_model.exterior_aperture_area / new_model.exterior_wall_area == \
        pytest.approx(0.6, rel=1e-3)
示例#20
0
def test_model_from_gbxml():
    runner = CliRunner()
    input_gbxml_model = os.path.abspath(
        './tests/gbxml/SampleGBXMLfromRevit.xml')

    result = runner.invoke(model_from_gbxml, [input_gbxml_model])
    assert result.exit_code == 0
    result_dict = json.loads(result.output)
    model = Model.from_dict(result_dict)
    assert isinstance(model, Model)
示例#21
0
def test_overhang():
    input_model = './tests/json/single_family_home.hbjson'
    runner = CliRunner()
    in_args = [input_model, '0.4', '-a', '10', '-vo', '0.5', '-i']
    result = runner.invoke(overhang, in_args)
    assert result.exit_code == 0

    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert all(len(ap.indoor_shades) == 1 for ap in new_model.apertures)
示例#22
0
def test_rectangle_plan_custom():
    runner = CliRunner()
    in_arg = ['30', '20', '3.5', '-p', '5', '-a', '135', '-ar', '-af']
    result = runner.invoke(rectangle_plan, in_arg)
    assert result.exit_code == 0
    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert new_model.units == 'Meters'
    assert len(new_model.rooms) == 5
    assert len(new_model.apertures) == 0
示例#23
0
def test_l_shaped_plan_detailed():
    runner = CliRunner()
    in_arg = ['20', '40', '15', '30', '3.5', '-p', '5', '-s', '3', '-a', '45']
    result = runner.invoke(l_shaped_plan, in_arg)
    assert result.exit_code == 0
    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert new_model.units == 'Meters'
    assert len(new_model.rooms) == 21
    assert len(new_model.apertures) == 0
示例#24
0
def test_louvers_by_count():
    input_model = './tests/json/single_family_home.hbjson'
    runner = CliRunner()
    in_args = [input_model, '2', '0.2', '-a', '-10', '-o', '0.05', '-i']
    result = runner.invoke(louvers_by_count, in_args)
    assert result.exit_code == 0

    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert all(len(ap.indoor_shades) == 2 for ap in new_model.apertures)
示例#25
0
def model_complete_single_zone_office_user_data(directory):
    room = Room.from_box('Tiny_House_Office', 5, 10, 3)
    room.properties.energy.program_type = prog_type_lib.office_program
    room.properties.energy.add_default_ideal_air()

    south_face = room[3]
    south_face.apertures_by_ratio(0.4, 0.01)
    south_face.apertures[0].overhang(0.5, indoor=False)
    south_face.apertures[0].overhang(0.5, indoor=True)
    south_face.move_shades(Vector3D(0, 0, -0.5))
    light_shelf_out = ShadeConstruction('Outdoor_Light_Shelf', 0.5, 0.5)
    light_shelf_in = ShadeConstruction('Indoor_Light_Shelf', 0.7, 0.7)
    south_face.apertures[0].outdoor_shades[0].properties.energy.construction = light_shelf_out
    south_face.apertures[0].indoor_shades[0].properties.energy.construction = light_shelf_in

    north_face = room[1]
    north_face.overhang(0.25, indoor=False)
    door_verts = [Point3D(2, 10, 0.1), Point3D(1, 10, 0.1),
                  Point3D(1, 10, 2.5), Point3D(2, 10, 2.5)]
    door = Door('Front_Door', Face3D(door_verts))
    north_face.add_door(door)

    aperture_verts = [Point3D(4.5, 10, 1), Point3D(2.5, 10, 1),
                      Point3D(2.5, 10, 2.5), Point3D(4.5, 10, 2.5)]
    aperture = Aperture('Front_Aperture', Face3D(aperture_verts))
    north_face.add_aperture(aperture)
    
    model = Model('Tiny_House', [room])
    model_dict = model.to_dict()

    model_dict['user_data'] = {'site': 'The backyard'}
    model_dict['rooms'][0]['user_data'] = {'alt_name': 'Little old tiny house'}
    model_dict['rooms'][0]['faces'][0]['user_data'] = {'alt_name': 'The floor'}
    model_dict['rooms'][0]['faces'][3]['apertures'][0]['user_data'] = \
        {'alt_name': 'Picture window'}
    model_dict['rooms'][0]['faces'][1]['doors'][0]['user_data'] = \
        {'alt_name': 'Front door'}
    model_dict['rooms'][0]['faces'][3]['apertures'][0]['outdoor_shades'][0]['user_data'] = \
        {'alt_name': 'Awning'}

    dest_file = os.path.join(directory, 'model_complete_user_data.json')
    with open(dest_file, 'w') as fp:
        json.dump(model.to_dict(), fp, indent=4)
示例#26
0
def test_to_dict_single_zone_detailed_loads():
    """Test the Model to_dict method with detailed, room-level loads."""
    room = Room.from_box('OfficeTestBox', 5, 10, 3)
    room.properties.energy.program_type = plenum_program
    room.properties.energy.add_default_ideal_air()

    room.properties.energy.people = office_program.people
    room.properties.energy.lighting = office_program.lighting
    room.properties.energy.electric_equipment = office_program.electric_equipment
    room.properties.energy.infiltration = office_program.infiltration
    room.properties.energy.ventilation = office_program.ventilation
    room.properties.energy.setpoint = office_program.setpoint

    room[0].boundary_condition = boundary_conditions.adiabatic
    room[1].boundary_condition = boundary_conditions.adiabatic
    room[2].boundary_condition = boundary_conditions.adiabatic
    room[4].boundary_condition = boundary_conditions.adiabatic
    room[5].boundary_condition = boundary_conditions.adiabatic

    model = Model('OfficeModel', [room])

    model_dict = model.to_dict()

    assert 'people' in model_dict['rooms'][0]['properties']['energy']
    assert model_dict['rooms'][0]['properties']['energy']['people']['identifier'] == \
        office_program.people.identifier
    assert 'lighting' in model_dict['rooms'][0]['properties']['energy']
    assert model_dict['rooms'][0]['properties']['energy']['lighting']['identifier'] == \
        office_program.lighting.identifier
    assert 'electric_equipment' in model_dict['rooms'][0]['properties'][
        'energy']
    assert model_dict['rooms'][0]['properties']['energy']['electric_equipment']['identifier'] == \
        office_program.electric_equipment.identifier
    assert 'infiltration' in model_dict['rooms'][0]['properties']['energy']
    assert model_dict['rooms'][0]['properties']['energy']['infiltration']['identifier'] == \
        office_program.infiltration.identifier
    assert 'ventilation' in model_dict['rooms'][0]['properties']['energy']
    assert model_dict['rooms'][0]['properties']['energy']['ventilation']['identifier'] == \
        office_program.ventilation.identifier
    assert 'setpoint' in model_dict['rooms'][0]['properties']['energy']
    assert model_dict['rooms'][0]['properties']['energy']['setpoint']['identifier'] == \
        office_program.setpoint.identifier
示例#27
0
def lighting_2004(model_json, output_file):
    """Convert a Model's lighting to be conformant with ASHRAE 90.1-2004 appendix G.

    This includes determining whether an ASHRAE 2004 equivalent exists for each
    program type in the model. If none is found, the baseline_watts_per_area on
    the room's program's lighting will be used, which will default to a typical
    office if none has been specified.

    \b
    Args:
        model_json: Full path to a Model JSON file.
    """
    try:
        # re-serialize the Model to Python and get the glazing ratios
        with open(model_json) as json_file:
            data = json.load(json_file)
        model = Model.from_dict(data)

        # loop through the rooms and try to find equivalent programs in 2004
        for room in model.rooms:
            if room.properties.energy.lighting is None:
                continue
            prog_name = room.properties.energy.program_type.identifier.split(
                '::')
            prog_2004 = None
            if len(prog_name) == 3:
                new_prog_name = '2004::{}::{}'.format(prog_name[1],
                                                      prog_name[2])
                try:
                    prog_2004 = program_type_by_identifier(new_prog_name)
                except ValueError:  # no equivalent program in ASHRAE 2004
                    pass
            if prog_2004 is not None:  # if program was found, use it to assign the LPD
                if prog_2004.lighting is not None:
                    dup_light = room.properties.energy.lighting.duplicate()
                    dup_light.watts_per_area = prog_2004.lighting.watts_per_area
            elif room.properties.energy.program_type.lighting is not None:
                dup_light = room.properties.energy.program_type.lighting.duplicate(
                )
                dup_light.watts_per_area = dup_light.baseline_watts_per_area
            else:
                dup_light = room.properties.energy.lighting.duplicate()
                dup_light.watts_per_area = dup_light.baseline_watts_per_area
            dup_light.identifier = '{}_Lighting'.format(room.identifier)
            room.properties.energy.lighting = dup_light

        # write the Model JSON string
        output_file.write(json.dumps(model.to_dict()))
    except Exception as e:
        _logger.exception(
            'Model baseline geometry creation failed.\n{}'.format(e))
        sys.exit(1)
    else:
        sys.exit(0)
示例#28
0
def test_rectangle_plan_simple():
    runner = CliRunner()
    result = runner.invoke(rectangle_plan, ['30', '20', '3.5'])
    assert result.exit_code == 0
    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert len(new_model.rooms) == 1
    assert len(new_model.apertures) == 0

    result = runner.invoke(rectangle_plan, ['30', '20', '3.5', '-p', '5'])
    assert result.exit_code == 0
    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert len(new_model.rooms) == 5

    result = runner.invoke(rectangle_plan, ['30', '20', '3.5', '-p', '10'])
    assert result.exit_code == 0
    model_dict = json.loads(result.output)
    new_model = Model.from_dict(model_dict)
    assert len(new_model.rooms) == 4
示例#29
0
def model_complete_multi_zone_office(directory):
    first_floor = Room.from_box('First_Floor', 10, 10, 3, origin=Point3D(0, 0, 0))
    second_floor = Room.from_box('Second_Floor', 10, 10, 3, origin=Point3D(0, 0, 3))
    first_floor.properties.energy.program_type = prog_type_lib.office_program
    second_floor.properties.energy.program_type = prog_type_lib.office_program
    first_floor.properties.energy.add_default_ideal_air()
    second_floor.properties.energy.add_default_ideal_air()
    for face in first_floor[1:5]:
        face.apertures_by_ratio(0.2, 0.01)
    for face in second_floor[1:5]:
        face.apertures_by_ratio(0.2, 0.01)

    pts_1 = [Point3D(0, 0, 6), Point3D(0, 10, 6), Point3D(10, 10, 6), Point3D(10, 0, 6)]
    pts_2 = [Point3D(0, 0, 6), Point3D(5, 0, 9), Point3D(5, 10, 9), Point3D(0, 10, 6)]
    pts_3 = [Point3D(10, 0, 6), Point3D(10, 10, 6), Point3D(5, 10, 9), Point3D(5, 0, 9)]
    pts_4 = [Point3D(0, 0, 6), Point3D(10, 0, 6), Point3D(5, 0, 9)]
    pts_5 = [Point3D(10, 10, 6), Point3D(0, 10, 6), Point3D(5, 10, 9)]
    face_1 = Face('AtticFace1', Face3D(pts_1))
    face_2 = Face('AtticFace2', Face3D(pts_2))
    face_3 = Face('AtticFace3', Face3D(pts_3))
    face_4 = Face('AtticFace4', Face3D(pts_4))
    face_5 = Face('AtticFace5', Face3D(pts_5))
    attic = Room('Attic', [face_1, face_2, face_3, face_4, face_5], 0.01, 1)

    constr_set = ConstructionSet('Attic Construction Set')
    polyiso = EnergyMaterial('PolyIso', 0.2, 0.03, 43, 1210, 'MediumRough')
    roof_constr = OpaqueConstruction('Attic Roof Construction',
                                     [roof_membrane, polyiso, wood])
    floor_constr = OpaqueConstruction('Attic Floor Construction',
                                      [wood, insulation, wood])
    constr_set.floor_set.interior_construction = floor_constr
    constr_set.roof_ceiling_set.exterior_construction = roof_constr
    attic.properties.energy.construction_set = constr_set

    Room.solve_adjacency([first_floor, second_floor, attic], 0.01)

    model = Model('Multi_Zone_Single_Family_House', [first_floor, second_floor, attic])

    dest_file = os.path.join(directory, 'model_complete_multi_zone_office.json')
    with open(dest_file, 'w') as fp:
        json.dump(model.to_dict(), fp, indent=4)
示例#30
0
def test_to_from_dict_methods():
    """Test the to/from dict methods."""
    room = Room.from_box('Tiny House Zone', 5, 10, 3)
    south_face = room[3]
    south_face.apertures_by_ratio(0.4, 0.01)
    south_face.apertures[0].overhang(0.5, indoor=False)
    south_face.apertures[0].overhang(0.5, indoor=True)
    south_face.apertures[0].move_shades(Vector3D(0, 0, -0.5))
    north_face = room[1]
    door_verts = [Point3D(2, 10, 0.1), Point3D(1, 10, 0.1),
                  Point3D(1, 10, 2.5), Point3D(2, 10, 2.5)]
    aperture_verts = [Point3D(4.5, 10, 1), Point3D(2.5, 10, 1),
                      Point3D(2.5, 10, 2.5), Point3D(4.5, 10, 2.5)]
    door = Door('Front Door', Face3D(door_verts))
    north_face.add_door(door)
    aperture = Aperture('Front Aperture', Face3D(aperture_verts))
    north_face.add_aperture(aperture)
    model = Model('Tiny House', [room])
    model.north_angle = 15

    model_dict = model.to_dict()
    new_model = Model.from_dict(model_dict)
    assert model_dict == new_model.to_dict()

    assert new_model.name == 'TinyHouse'
    assert new_model.display_name == 'Tiny House'
    assert new_model.north_angle == 15
    assert len(new_model.rooms) == 1
    assert isinstance(new_model.rooms[0], Room)
    assert len(new_model.faces) == 6
    assert isinstance(new_model.faces[0], Face)
    assert len(new_model.shades) == 2
    assert isinstance(new_model.shades[0], Shade)
    assert len(new_model.apertures) == 2
    assert isinstance(new_model.apertures[0], Aperture)
    assert len(new_model.doors) == 1
    assert isinstance(new_model.doors[0], Door)
    assert len(new_model.orphaned_faces) == 0
    assert len(new_model.orphaned_shades) == 0
    assert len(new_model.orphaned_apertures) == 0
    assert len(new_model.orphaned_doors) == 0