Example #1
0
def generate_intersection_data(_shade_mesh, _win_mesh_back, _points, _sky_vecs,
                               _normals, _parallel):
    """Creates all the Intersection Matrix data for both the Shaded and the UNShaded conditions

    Note that for the 'Unshaded' case you still have to pass the solver *something*, so 
    the _win_mesh_back is used for this case. This surface should block out any radiation coming from
    'behind' and also not interfer with the front-side radition calculation.
    
    Adapted from Ladybug 'IncidentRadiation' Component
    
    Arguments:
        _shade_mesh: (Mesh) The context shading joined mesh
        _win_mesh_back: (Mesh) The window surface pushed 'back' a little.
        _points: (_)     
        _sky_vecs: (_)
        _normals: (list: Ladybug Normals)
        _parallel: (bool)
    Returns: (tuple)
        int_matrix_init_shaded: Intersection Matrix for window WITH shading
        int_matrix_init_unshaded: Intersection Matrix for window WITHOUT shading
        angles_s: Shaded
        angles_u: UN-Shaded
    """

    # intersect the rays with the mesh
    #---------------------------------------------------------------------------
    int_matrix_init_shaded, angles_s = intersect_mesh_rays(_shade_mesh,
                                                           _points,
                                                           _sky_vecs,
                                                           _normals,
                                                           parallel=_parallel)

    int_matrix_init_unshaded, angles_u = intersect_mesh_rays(
        _win_mesh_back, _points, _sky_vecs, _normals, parallel=_parallel)

    return int_matrix_init_shaded, int_matrix_init_unshaded, angles_s, angles_u
Example #2
0
        patch_wghts = view_sphere.sphere_patch_weights(_resolution_)
    else:
        patch_mesh, lb_vecs = view_sphere.dome_patches(_resolution_)
        patch_wghts = view_sphere.dome_patch_weights(_resolution_)
    view_vecs = [from_vector3d(pt) for pt in lb_vecs]

    # mesh the geometry and context
    shade_mesh = join_geometry_to_mesh(_geometry + context_) if _geo_block_ \
        else join_geometry_to_mesh(context_)

    # intersect the rays with the mesh
    if vt_str == 'Sky View':  # account for the normals of the surface
        normals = [from_vector3d(vec) for vec in study_mesh.face_normals]
        int_matrix, angles = intersect_mesh_rays(shade_mesh,
                                                 points,
                                                 view_vecs,
                                                 normals,
                                                 parallel=parallel_)
    else:
        int_matrix, angles = intersect_mesh_rays(shade_mesh,
                                                 points,
                                                 view_vecs,
                                                 parallel=parallel_)

    # compute the results
    int_mtx = objectify_output('View Intersection Matrix', int_matrix)
    vec_count = len(view_vecs)
    results = []
    if vt_str == 'Sky View':  # weight intersections by angle before output
        for int_vals, angles in zip(int_matrix, angles):
            w_res = (ival * 2 * math.cos(ang)
    ground_rad = [(sum(total_sky_rad) / len(total_sky_rad)) * mtx[0][1]
                  ] * len(total_sky_rad)
    all_rad = total_sky_rad + ground_rad
    lb_vecs = view_sphere.tregenza_dome_vectors if len(total_sky_rad) == 145 \
        else view_sphere.reinhart_dome_vectors
    if mtx[0][0] != 0:  # there is a north input for sky; rotate vectors
        north_angle = math.radians(mtx[0][0])
        lb_vecs = tuple(vec.rotate_xy(north_angle) for vec in lb_vecs)
    lb_grnd_vecs = tuple(vec.reverse() for vec in lb_vecs)
    all_vecs = [from_vector3d(vec) for vec in lb_vecs + lb_grnd_vecs]

    # intersect the rays with the mesh
    normals = [from_vector3d(vec) for vec in study_mesh.face_normals]
    int_matrix_init, angles = intersect_mesh_rays(shade_mesh,
                                                  points,
                                                  all_vecs,
                                                  normals,
                                                  cpu_count=workers)

    # compute the results
    results = []
    int_matrix = []
    for int_vals, angles in zip(int_matrix_init, angles):
        pt_rel = [ival * math.cos(ang) for ival, ang in zip(int_vals, angles)]
        int_matrix.append(pt_rel)
        rad_result = sum(r * w for r, w in zip(pt_rel, all_rad))
        results.append(rad_result)

    # output the intersection matrix and compute total radiation
    int_mtx = objectify_output('Geometry/Sky Intersection Matrix', int_matrix)
    unit_conv = conversion_to_meters()**2
Example #4
0
        from_point3d(pt.move(vec * _offset_dist_))
        for pt, vec in zip(study_mesh.face_centroids, study_mesh.face_normals)
    ]
    hide_output(ghenv.Component, 1)

    # mesh the geometry and context
    shade_mesh = join_geometry_to_mesh(_geometry + context_)

    # get the study points and reverse the sun vectors (for backward ray-tracting)
    rev_vec = [from_vector3d(to_vector3d(vec).reverse()) for vec in _vectors]
    normals = [from_vector3d(vec) for vec in study_mesh.face_normals]

    # intersect the rays with the mesh
    int_matrix, angles = intersect_mesh_rays(shade_mesh,
                                             points,
                                             rev_vec,
                                             normals,
                                             parallel=parallel_)

    # compute the results
    int_mtx = objectify_output('Sun Intersection Matrix', int_matrix)
    if _timestep_ and _timestep_ != 1:  # divide by the timestep before output
        results = [sum(int_list) / _timestep_ for int_list in int_matrix]
    else:  # no division required
        results = [sum(int_list) for int_list in int_matrix]

    # create the mesh and legend outputs
    graphic = GraphicContainer(results, study_mesh.min, study_mesh.max,
                               legend_par_)
    graphic.legend_parameters.title = 'hours'
    if legend_par_ is None or legend_par_.are_colors_default:
Example #5
0
    mtx = de_objectify_output(_sky_mtx)
    total_sky_rad = [
        dir_rad + dif_rad for dir_rad, dif_rad in zip(mtx[1], mtx[2])
    ]
    lb_vecs = view_sphere.tregenza_dome_vectors if len(total_sky_rad) == 145 \
        else view_sphere.reinhart_dome_vectors
    if mtx[0][0] != 0:  # there is a north input for sky; rotate vectors
        north_angle = math.radians(mtx[0][0])
        lb_vecs = [vec.rotate_xy(north_angle) for vec in lb_vecs]
    sky_vecs = [from_vector3d(vec) for vec in lb_vecs]

    # intersect the rays with the mesh
    normals = [from_vector3d(vec) for vec in study_mesh.face_normals]
    int_matrix_init, angles = intersect_mesh_rays(shade_mesh,
                                                  points,
                                                  sky_vecs,
                                                  normals,
                                                  parallel=parallel_)

    # compute the results
    results = []
    int_matrix = []
    for int_vals, angles in zip(int_matrix_init, angles):
        pt_rel = [ival * math.cos(ang) for ival, ang in zip(int_vals, angles)]
        int_matrix.append(pt_rel)
        rad_result = sum(r * w for r, w in zip(pt_rel, total_sky_rad))
        results.append(rad_result)

    # output the intersection matrix and compute total radiation
    int_mtx = objectify_output('Geometry/Sky Intersection Matrix', int_matrix)
    unit_conv = conversion_to_meters()**2
Example #6
0
        from_point3d(pt.move(vec * _offset_dist_))
        for pt, vec in zip(study_mesh.face_centroids, study_mesh.face_normals)
    ]
    hide_output(ghenv.Component, 1)

    # mesh the geometry and context
    shade_mesh = join_geometry_to_mesh(_geometry + context_)

    # get the study points and reverse the sun vectors (for backward ray-tracting)
    rev_vec = [from_vector3d(to_vector3d(vec).reverse()) for vec in _vectors]
    normals = [from_vector3d(vec) for vec in study_mesh.face_normals]

    # intersect the rays with the mesh
    int_matrix, angles = intersect_mesh_rays(shade_mesh,
                                             points,
                                             rev_vec,
                                             normals,
                                             cpu_count=workers)

    # compute the results
    int_mtx = objectify_output('Sun Intersection Matrix', int_matrix)
    if _timestep_ and _timestep_ != 1:  # divide by the timestep before output
        results = [sum(int_list) / _timestep_ for int_list in int_matrix]
    else:  # no division required
        results = [sum(int_list) for int_list in int_matrix]

    # create the mesh and legend outputs
    graphic = GraphicContainer(results, study_mesh.min, study_mesh.max,
                               legend_par_)
    graphic.legend_parameters.title = 'hours'
    if legend_par_ is None or legend_par_.are_colors_default:
        # mesh the context for the intersection calculation
        shade_mesh = join_geometry_to_mesh(_context)

        # generate the sun vectors for each sun-up hour of the year
        sp = Sunpath.from_location(_location, north_)
        sun_vecs = []
        day_pattern = []
        for hoy in range(8760):
            sun = sp.calculate_sun_from_hoy(hoy)
            day_pattern.append(sun.is_during_day)
            if sun.is_during_day:
                sun_vecs.append(from_vector3d(sun.sun_vector_reversed))

        # intersect the sun vectors with the context and compute fraction exposed
        sun_int_matrix, angles = intersect_mesh_rays(shade_mesh,
                                                     human_points,
                                                     sun_vecs,
                                                     cpu_count=workers)
        fract_body_exp = []
        for i in range(0, len(human_points), _pt_count_):
            fract_body_exp.append(
                fract_exposed_from_mtx(sun_int_matrix[i:i + _pt_count_],
                                       day_pattern))

        # generate the vectors and weights for sky exposure
        sky_vecs = [
            from_vector3d(vec) for vec in view_sphere.tregenza_dome_vectors
        ]
        patch_wghts = view_sphere.dome_patch_weights(1)

        # compute the sky exposure
        sky_int_matrix, angles = intersect_mesh_rays(shade_mesh,
                                    orient_pattern)
            apply_mask_to_sky(sky_pattern, over_pattern)
        if left_fin_proj_ or right_fin_proj_:
            f_pattern = view_sphere.fin_pattern(direction, left_fin_proj_,
                                                right_fin_proj_, view_vecs)
            apply_mask_to_base_mask(strategy_pattern, f_pattern,
                                    orient_pattern)
            apply_mask_to_sky(sky_pattern, f_pattern)

# account for any input context
context_pattern = None
if len(context_) != 0:
    shade_mesh = join_geometry_to_mesh(context_)  # mesh the context
    points = [from_point3d(center_pt3d)]
    view_vecs = [from_vector3d(pt) for pt in view_vecs]
    int_matrix, angles = intersect_mesh_rays(shade_mesh, points, view_vecs)
    context_pattern = [val == 0 for val in int_matrix[0]]
    apply_mask_to_sky(sky_pattern, context_pattern)

# get the weights for each patch to be used in view factor calculation
weights = view_sphere.dome_radial_patch_weights(az_count, alt_count)
if direction is not None:
    weights = [
        wgt * abs(math.cos(ang)) * 2 for wgt, ang in zip(weights, dir_angles)
    ]

# create meshes for the masks and compute any necessary view factors
gray, black = Color(230, 230, 230), Color(0, 0, 0)
context_view, orient_view, strategy_view = 0, 0, 0
if context_pattern is not None:
    context_mask = mask_mesh_from_pattern(sky_mask, context_pattern, black)
        # mesh the context for the intersection calculation
        shade_mesh = join_geometry_to_mesh(_context)

        # generate the sun vectors for each sun-up hour of the year
        sp = Sunpath.from_location(_location, north_)
        sun_vecs = []
        day_pattern = []
        for hoy in range(8760):
            sun = sp.calculate_sun_from_hoy(hoy)
            day_pattern.append(sun.is_during_day)
            if sun.is_during_day:
                sun_vecs.append(from_vector3d(sun.sun_vector_reversed))

        # intersect the sun vectors with the context and compute fraction exposed
        sun_int_matrix, angles = intersect_mesh_rays(shade_mesh,
                                                     human_points,
                                                     sun_vecs,
                                                     parallel=parallel_)
        fract_body_exp = []
        for i in range(0, len(human_points), _pt_count_):
            fract_body_exp.append(
                fract_exposed_from_mtx(sun_int_matrix[i:i + _pt_count_],
                                       day_pattern))

        # generate the vectors and weights for sky exposure
        sky_vecs = [
            from_vector3d(vec) for vec in view_sphere.tregenza_dome_vectors
        ]
        patch_wghts = view_sphere.dome_patch_weights(1)

        # compute the sky exposure
        sky_int_matrix, angles = intersect_mesh_rays(shade_mesh,