def test_find_adjacency(): """Test the find adjacency method.""" room_south = Room.from_box('SouthZone', 5, 5, 3, origin=Point3D(0, 0, 0)) room_north = Room.from_box('NorthZone', 5, 5, 3, origin=Point3D(0, 5, 0)) assert room_south[1].boundary_condition == boundary_conditions.outdoors assert room_north[3].boundary_condition == boundary_conditions.outdoors adj_faces = Room.find_adjacency([room_south, room_north], 0.01) assert len(adj_faces) == 1 assert len(adj_faces[0]) == 2 adj_info = Room.solve_adjacency([room_south, room_north], 0.01) # make sure it all still works after the Surface BC is already set adj_faces = Room.find_adjacency([room_south, room_north], 0.01) assert len(adj_faces) == 1 assert len(adj_faces[0]) == 2
def solve_adjacency(model_json, wall, surface, no_overwrite, output_file): """Solve adjacency between Rooms of a Model JSON file. \b Args: model_json: Full path to a Model JSON file. """ try: # serialize the Model to Python with open(model_json) as json_file: data = json.load(json_file) parsed_model = Model.from_dict(data) # check the Model tolerance assert parsed_model.tolerance != 0, \ 'Model must have a non-zero tolerance to use solve-adjacency.' tol = parsed_model.tolerance # solve adjacency if no_overwrite: # only assign new adjacencies adj_info = Room.solve_adjacency(parsed_model.rooms, tol) else: # overwrite existing Surface BC adj_faces = Room.find_adjacency(parsed_model.rooms, tol) for face_pair in adj_faces: face_pair[0].set_adjacency(face_pair[1]) adj_info = {'adjacent_faces': adj_faces} # try to assign the air boundary face type if not wall: for face_pair in adj_info['adjacent_faces']: if isinstance(face_pair[0].type, Wall): face_pair[0].type = face_types.air_boundary face_pair[1].type = face_types.air_boundary # try to assign the adiabatic boundary condition if not surface and ad_bc: for face_pair in adj_info['adjacent_faces']: face_pair[0].boundary_condition = ad_bc face_pair[1].boundary_condition = ad_bc # write the new model out to the file or stdout output_file.write(json.dumps(parsed_model.to_dict())) except Exception as e: _logger.exception('Model solve adjacency failed.\n{}'.format(e)) sys.exit(1) else: sys.exit(0)
ap_pair[0].properties.energy.modifier = rad_int_mod[3] if rad_int_mod[4] is not None: apply_mod_to_door(adj_info['adjacent_doors'], rad_int_mod[4], False) if rad_int_mod[5] is not None: apply_mod_to_door(adj_info['adjacent_doors'], rad_int_mod[5], True) if all_required_inputs(ghenv.Component) and _run: adj_rooms = [room.duplicate() for room in _rooms] # duplicate the initial objects # solve adjacnecy if overwrite_: # find adjscencies and re-assign them adj_aps = [] adj_doors = [] adj_faces = Room.find_adjacency(adj_rooms, tolerance) for face_pair in adj_faces: face_info = face_pair[0].set_adjacency(face_pair[1]) adj_aps.extend(face_info['adjacent_apertures']) adj_doors.extend(face_info['adjacent_doors']) adj_info = { 'adjacent_faces': adj_faces, 'adjacent_apertures': adj_aps, 'adjacent_doors': adj_doors } else: # just solve for new adjacencies adj_info = Room.solve_adjacency(adj_rooms, tolerance) # try to assign the energyplus constructions if specified if len(ep_int_constr_) != 0: apply_ep_int_constr(adj_info, ep_int_constr_)