def test_from_dict_vent_opening(): """Test the Room2D from_dict method with ventilation opening energy properties.""" pts = (Point3D(0, 0, 3), Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(0, 10, 3)) ashrae_base = SimpleWindowRatio(0.4) room = Room2D('SquareShoebox', Face3D(pts), 3) room.set_outdoor_window_parameters(ashrae_base) ventilation = VentilationControl() ventilation.min_indoor_temperature = 22 ventilation.max_indoor_temperature = 28 ventilation.min_outdoor_temperature = 12 ventilation.max_outdoor_temperature = 32 ventilation.delta_temperature = 0 opening = VentilationOpening() opening.fraction_area_operable = 0.25 opening.fraction_height_operable = 0.5 opening.wind_cross_vent = True room.properties.energy.window_vent_control = ventilation room.properties.energy.window_vent_opening = opening rd = room.to_dict() new_room = Room2D.from_dict(rd) assert new_room.to_dict() == rd
def test_set_window_opening(): """Test the setting of window openings on a Room2D.""" pts = (Point3D(0, 0, 3), Point3D(10, 0, 3), Point3D(10, 10, 3), Point3D(0, 10, 3)) ashrae_base = SimpleWindowRatio(0.4) room = Room2D('SquareShoebox', Face3D(pts), 3) room.set_outdoor_window_parameters(ashrae_base) ventilation = VentilationControl() ventilation.min_indoor_temperature = 22 ventilation.max_indoor_temperature = 28 ventilation.min_outdoor_temperature = 12 ventilation.max_outdoor_temperature = 32 ventilation.delta_temperature = 0 opening = VentilationOpening() opening.fraction_area_operable = 0.25 opening.fraction_height_operable = 0.5 opening.wind_cross_vent = True room.properties.energy.window_vent_control = ventilation room.properties.energy.window_vent_opening = opening hb_room, adj = room.to_honeybee() assert hb_room.properties.energy.window_vent_control == ventilation assert hb_room[1].apertures[0].properties.energy.vent_opening == opening
def test_ventilation_opening_equality(): """Test the equality of Ventilation objects.""" ventilation = VentilationOpening(0.25, 0.5, 0.25, True, 0.001, 0.667, 1e-3) ventilation_dup = ventilation.duplicate() ventilation_alt = VentilationOpening(0.5, 0.5, 0.25, True, 0.001, 0.667, 1e-3) assert ventilation is ventilation assert ventilation is not ventilation_dup assert ventilation == ventilation_dup ventilation_dup.fraction_area_operable = 0.3 assert ventilation != ventilation_dup assert ventilation != ventilation_alt
def test_ventilation_opening_afn_init(): """Test the initialization of VentilationOpening and basic properties for AFN.""" vent_afn = VentilationOpening( fraction_area_operable=1, fraction_height_operable=1, discharge_coefficient=0.17, wind_cross_vent=False, flow_coefficient_closed=0.001, flow_exponent_closed=0.667, two_way_threshold=0.0001) assert vent_afn.flow_coefficient_closed == pytest.approx(0.001, abs=1e-10) assert vent_afn.flow_exponent_closed == pytest.approx(0.667, abs=1e-10) assert vent_afn.two_way_threshold == pytest.approx(0.0001) # Test setting values with pytest.raises(AssertionError): vent_afn.flow_coefficient_closed = -1 with pytest.raises(AssertionError): vent_afn.flow_exponent_closed = 0.1 with pytest.raises(AssertionError): vent_afn.two_way_threshold = -1 vent_afn.flow_coefficient_closed = 0.002 vent_afn.flow_exponent_closed = 0.65 vent_afn.two_way_threshold = 0.001 assert vent_afn.flow_coefficient_closed == pytest.approx(0.002, abs=1e-10) assert vent_afn.flow_exponent_closed == pytest.approx(0.65, abs=1e-10) assert vent_afn.two_way_threshold == pytest.approx(0.001)
def model_energy_window_ventilation(directory): room = Room.from_box('TinyHouseZone', 5, 10, 3) room.properties.energy.add_default_ideal_air() south_face = room[3] north_face = room[1] south_face.apertures_by_ratio(0.4, 0.01) north_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].is_operable = True north_face.apertures[0].is_operable = True heat_setpt = ScheduleRuleset.from_constant_value( 'House Heating', 20, schedule_types.temperature) cool_setpt = ScheduleRuleset.from_constant_value( 'House Cooling', 28, schedule_types.temperature) setpoint = Setpoint('House Setpoint', heat_setpt, cool_setpt) room.properties.energy.setpoint = setpoint vent_control = VentilationControl(22, 27, 12, 30) room.properties.energy.window_vent_control = vent_control ventilation = VentilationOpening(wind_cross_vent=True) room.properties.energy.assign_ventilation_opening(ventilation) model = Model('TinyHouse', [room]) dest_file = os.path.join(directory, 'model_energy_window_ventilation.json') with open(dest_file, 'w') as fp: json.dump(model.to_dict(included_prop=['energy']), fp, indent=4)
def test_run_idf_window_ventilation(): """Test the Model.to.idf and run_idf method with a model possessing operable windows.""" room = Room.from_box('TinyHouseZone', 5, 10, 3) room.properties.energy.add_default_ideal_air() south_face = room[3] north_face = room[1] south_face.apertures_by_ratio(0.4, 0.01) north_face.apertures_by_ratio(0.4, 0.01) south_face.apertures[0].is_operable = True north_face.apertures[0].is_operable = True heat_setpt = ScheduleRuleset.from_constant_value( 'House Heating', 20, schedule_types.temperature) cool_setpt = ScheduleRuleset.from_constant_value( 'House Cooling', 28, schedule_types.temperature) setpoint = Setpoint('House Setpoint', heat_setpt, cool_setpt) room.properties.energy.setpoint = setpoint vent_control = VentilationControl(22, 27, 12, 30) room.properties.energy.window_vent_control = vent_control ventilation = VentilationOpening(wind_cross_vent=True) op_aps = room.properties.energy.assign_ventilation_opening(ventilation) assert len(op_aps) == 2 model = Model('TinyHouse', [room]) # Get the input SimulationParameter sim_par = SimulationParameter() sim_par.output.add_zone_energy_use() ddy_file = './tests/ddy/chicago.ddy' sim_par.sizing_parameter.add_from_ddy_996_004(ddy_file) sim_par.run_period.end_date = Date(6, 7) sim_par.run_period.start_date = Date(6, 1) # create the IDF string for simulation paramters and model idf_str = '\n\n'.join((sim_par.to_idf(), model.to.idf(model))) # write the final string into an IDF idf = os.path.join(folders.default_simulation_folder, 'test_file_window_vent', 'in.idf') write_to_file(idf, idf_str, True) # prepare the IDF for simulation epw_file = './tests/simulation/chicago.epw' prepare_idf_for_simulation(idf, epw_file) # run the IDF through EnergyPlus sql, zsz, rdd, html, err = run_idf(idf, epw_file) assert os.path.isfile(sql) assert os.path.isfile(err) err_obj = Err(err) assert 'EnergyPlus Completed Successfully' in err_obj.file_contents
def test_ventilation_opening_to_idf(): """Test the initialization of Ventilation from_idf.""" room = Room.from_box('ShoeBoxZone', 5, 10, 3) south_face = room[3] south_face.apertures_by_ratio(0.4, 0.01) aperture = south_face.apertures[0] aperture.is_operable = True simple_office = ScheduleDay('Simple Flush', [1, 0, 1], [Time(0, 0), Time(9, 0), Time(22, 0)]) schedule = ScheduleRuleset('Night Flush Schedule', simple_office, None, schedule_types.fractional) vent_control = VentilationControl(18, schedule=schedule) room.properties.energy.window_vent_control = vent_control ventilation = VentilationOpening() with pytest.raises(AssertionError): ventilation.to_idf() aperture.properties.energy.vent_opening = ventilation idf_str = ventilation.to_idf() assert room.identifier in idf_str assert schedule.identifier in idf_str
def _deserialize_window_vent(new_prop, data): """Re-serialize window ventilation objects from a dict and apply to new_prop. Args: new_prop: A Room2DEnergyProperties to apply the window ventilation to. data: A dictionary representation of Room2DEnergyProperties. """ if 'window_vent_control' in data and data[ 'window_vent_control'] is not None: new_prop.window_vent_control = \ VentilationControl.from_dict_abridged(data['window_vent_control'], {}) if 'window_vent_opening' in data and data[ 'window_vent_opening'] is not None: new_prop.window_vent_opening = \ VentilationOpening.from_dict(data['window_vent_opening'])
def test_ventilation_dict_methods(): """Test the to/from dict methods.""" ventilation = VentilationOpening(0.25, 0.5, 0.25, True) vent_dict = ventilation.to_dict() print(vent_dict) new_ventilation = VentilationOpening.from_dict(vent_dict) assert new_ventilation == ventilation assert vent_dict == new_ventilation.to_dict() # Test with afn ventilation_afn = VentilationOpening(1, 1, 0.17, False, 0.001, 0.667, 1e-3) vent_afn_dict = ventilation_afn.to_dict() vent_afn_dict['flow_coefficient_closed'] == pytest.approx(0.002, abs=1e-10) vent_afn_dict['flow_exponent_closed'] == pytest.approx(0.667, abs=1e-10) vent_afn_dict['two_way_threshold'] == pytest.approx(0.0001) new_ventilation_afn = VentilationOpening.from_dict(vent_afn_dict) assert new_ventilation_afn == ventilation_afn assert vent_afn_dict == new_ventilation_afn.to_dict()
def test_ventilation_opening_parent(): """Test the VentilationOpening with a parent.""" room = Room.from_box('ShoeBoxZone', 5, 10, 3) south_face = room[3] south_face.apertures_by_ratio(0.4, 0.01) aperture = south_face.apertures[0] ventilation = VentilationOpening() assert not ventilation.has_parent assert ventilation.parent is None with pytest.raises(AssertionError): aperture.properties.energy.vent_opening = ventilation aperture.is_operable = True aperture.properties.energy.vent_opening = ventilation assert ventilation.has_parent assert ventilation.parent.identifier == aperture.identifier
def test_ventilation_opening_init(): """Test the initialization of VentilationOpening and basic properties.""" ventilation = VentilationOpening() str(ventilation) # test the string representation assert ventilation.fraction_area_operable == 0.5 assert ventilation.fraction_height_operable == 1.0 assert ventilation.discharge_coefficient == 0.45 assert not ventilation.wind_cross_vent assert not ventilation.has_parent assert ventilation.parent is None ventilation.fraction_area_operable = 0.25 ventilation.fraction_height_operable = 0.5 ventilation.discharge_coefficient = 0.25 ventilation.wind_cross_vent = True assert ventilation.fraction_area_operable == 0.25 assert ventilation.fraction_height_operable == 0.5 assert ventilation.discharge_coefficient == 0.25 assert ventilation.wind_cross_vent
def ventilation_opening_default(directory): ventilation = VentilationOpening() dest_file = os.path.join(directory, 'ventilation_opening_default.json') with open(dest_file, 'w') as fp: json.dump(ventilation.to_dict(), fp, indent=4)
def model_energy_afn_multizone(directory): # south Room szone_pts = Face3D( [Point3D(0, 0), Point3D(20, 0), Point3D(20, 10), Point3D(0, 10)]) sroom = Room.from_polyface3d('SouthRoom', Polyface3D.from_offset_face(szone_pts, 3)) # north Room nzone_pts = Face3D( [Point3D(0, 10), Point3D(20, 10), Point3D(20, 20), Point3D(0, 20)]) nroom = Room.from_polyface3d('NorthRoom', Polyface3D.from_offset_face(nzone_pts, 3)) # add exterior windows on east/west faces sroom[2].apertures_by_ratio(0.3) nroom[4].apertures_by_ratio(0.3) sroom[2].apertures[0].is_operable = True nroom[4].apertures[0].is_operable = True # add small interior windows on north/south faces sroom[3].apertures_by_ratio(0.15) nroom[1].apertures_by_ratio(0.15) sroom[3].apertures[0].is_operable = True nroom[1].apertures[0].is_operable = True # ventilation openings vent_openings = VentilationOpening(fraction_area_operable=1, fraction_height_operable=1, discharge_coefficient=0.6, wind_cross_vent=False, flow_coefficient_closed=0.001, flow_exponent_closed=0.667, two_way_threshold=0.0001) sroom.properties.energy.assign_ventilation_opening(vent_openings) nroom.properties.energy.assign_ventilation_opening( vent_openings.duplicate()) # make ventilation control heat_setpt = ScheduleRuleset.from_constant_value( 'House Heating', 20, schedule_types.temperature) cool_setpt = ScheduleRuleset.from_constant_value( 'House Cooling', 28, schedule_types.temperature) setpoint = Setpoint('House Setpoint', heat_setpt, cool_setpt) sroom.properties.energy.setpoint = setpoint nroom.properties.energy.setpoint = setpoint.duplicate() vent_control = VentilationControl(22, 27, 12, 30) sroom.properties.energy.window_vent_control = vent_control nroom.properties.energy.window_vent_control = vent_control.duplicate() # rooms rooms = [sroom, nroom] for room in rooms: # Add program and hvac room.properties.energy.program_type = prog_type_lib.office_program # make model model = Model('Two_Zone_Simple', rooms) vsc = VentilationSimulationControl( vent_control_type='MultiZoneWithoutDistribution', building_type='LowRise', long_axis_angle=0, aspect_ratio=1) model.properties.energy.ventilation_simulation_control = vsc # make interior faces Room.solve_adjacency(rooms, 0.01) # make afn afn.generate(model.rooms) dest_file = os.path.join(directory, 'model_energy_afn.json') with open(dest_file, 'w') as fp: json.dump(model.to_dict(included_prop=['energy']), fp, indent=4)
if all_required_inputs(ghenv.Component): # loop through the rooms and assign the objects op_count = 0 rooms = [] for i, room_init in enumerate(_rooms): room = room_init.duplicate() # duplicate to avoid editing the input # assign the ventilation control for the windows room.properties.energy.window_vent_control = longest_list(_vent_cntrl, i) # create the base ventilation opening f_area = 0.5 if len(_fract_area_oper_) == 0 else longest_list(_fract_area_oper_, i) f_height = 1.0 if len(_fract_height_oper_) == 0 else longest_list(_fract_height_oper_, i) discharge = 0.45 if len(_discharge_coeff_) == 0 else longest_list(_discharge_coeff_, i) vent_open = VentilationOpening(f_area, f_height, discharge) # assign the cross ventilation cross_vent = longest_list(_wind_cross_vent_, i) if \ len(_wind_cross_vent_) != 0 else None if cross_vent is None: # analyze normals of room's apertures to test if cross vent is possible orient_angles = [] for face in room.faces: for ap in face.apertures: if ap.is_operable: try: orient_angles.append(ap.horizontal_orientation()) except ZeroDivisionError: orient_angles.append(0) if len(orient_angles) != 0:
try: from ladybug_rhino.grasshopper import all_required_inputs, give_warning except ImportError as e: raise ImportError('\nFailed to import ladybug_rhino:\n\t{}'.format(e)) def extract_room2ds(obj): """Get all of the Room2Ds assinged to a given dragonfly object.""" if isinstance(obj, Building): return obj.unique_room_2ds elif isinstance(obj, Story): return obj.room_2ds return [obj] # assume that the object is already a Room2D if all_required_inputs(ghenv.Component): # duplicate the initial objects df_objs = [obj.duplicate() for obj in _df_objs] # create the base ventilation opening f_area = 0.5 if _fract_area_oper_ is None else _fract_area_oper_ f_height = 1.0 if _fract_height_oper_ is None else _fract_height_oper_ discharge = 0.45 if _discharge_coeff_ is None else _discharge_coeff_ cross_vent = False if _wind_cross_vent_ is None else _wind_cross_vent_ vent_open = VentilationOpening(f_area, f_height, discharge, cross_vent) for obj in df_objs: for room in extract_room2ds(obj): room.properties.energy.window_vent_control = _vent_cntrl room.properties.energy.window_vent_opening = vent_open