Ejemplo n.º 1
0
def _calculate_f_e(info, tables , e):
    f_e = np.zeros(shape=(2,1))

    e_tab = tables.edge_to_global
    f1 = e_tab[e, 3] #numbers of functions in T^(r) -> linear_trial_funcs[f1]
    f2 = e_tab[e, 4]

    i1 = e_tab[e, 0]
    i2 = e_tab[e, 1]
    nr = e_tab[e, 2]

    x1 = tables.nodes_to_coordinates[i1, 0]
    y1 = tables.nodes_to_coordinates[i1, 1]

    x2 = tables.nodes_to_coordinates[i2, 0]
    y2 = tables.nodes_to_coordinates[i2, 1]

    length = math.sqrt((x2-x1)**2+(y2-y1)**2)

    integ2 = lambda xi: dn_funcs[nr](_ref_e_to_global(x1, x2, y1, y2, xi))*linear_trial_funcs_1D[1](xi) * length
    integ1 = lambda xi: dn_funcs[nr](_ref_e_to_global(x1, x2, y1, y2, xi))*linear_trial_funcs_1D[0](xi) * length

    f_e[0] = numeric.gauss_1D_6(integ1)
    f_e[1] = numeric.gauss_1D_6(integ2)


    return f_e
Ejemplo n.º 2
0
def _calculate_f_e(info, tables, e):
    f_e = np.zeros(shape=(2, 1))

    e_tab = tables.edge_to_global
    f1 = e_tab[e, 3]  #numbers of functions in T^(r) -> linear_trial_funcs[f1]
    f2 = e_tab[e, 4]

    i1 = e_tab[e, 0]
    i2 = e_tab[e, 1]
    nr = e_tab[e, 2]

    x1 = tables.nodes_to_coordinates[i1, 0]
    y1 = tables.nodes_to_coordinates[i1, 1]

    x2 = tables.nodes_to_coordinates[i2, 0]
    y2 = tables.nodes_to_coordinates[i2, 1]

    length = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)

    integ2 = lambda xi: dn_funcs[nr](_ref_e_to_global(x1, x2, y1, y2, xi)
                                     ) * linear_trial_funcs_1D[1](xi) * length
    integ1 = lambda xi: dn_funcs[nr](_ref_e_to_global(x1, x2, y1, y2, xi)
                                     ) * linear_trial_funcs_1D[0](xi) * length

    f_e[0] = numeric.gauss_1D_6(integ1)
    f_e[1] = numeric.gauss_1D_6(integ2)

    return f_e
Ejemplo n.º 3
0
def assemble_equations(local_to_global, nodes_to_coordinates, borders, eps,
                       rho, neumann):
    """
    Assembles the final system of linear equations to be solved.
    Outputs a Matrix K_h and the right hand side vector f_h
    """

    N_nodes = nodes_to_coordinates.shape[0]
    N_fe = local_to_global.shape[0]

    K_h = np.zeros(shape=(N_nodes, N_nodes))
    f_h = np.zeros(shape=(N_nodes, 1))

    for r in range(0, N_fe):

        #K_r, f_r for each element
        i1 = local_to_global[r, 0]
        i2 = local_to_global[r, 1]
        i3 = local_to_global[r, 2]
        x1 = nodes_to_coordinates[i1, 0]
        x2 = nodes_to_coordinates[i2, 0]
        x3 = nodes_to_coordinates[i3, 0]
        y1 = nodes_to_coordinates[i1, 1]
        y2 = nodes_to_coordinates[i2, 1]
        y3 = nodes_to_coordinates[i3, 1]

        K_r = _calculate_K_r(x1, x2, x3, y1, y2, y3, eps)
        f_r = _calculate_f_r(x1, x2, x3, y1, y2, y3, rho)

        for alpha in range(0, 3):
            i = local_to_global[r, alpha]

            f_h[i, 0] = f_h[i, 0] + f_r[alpha, 0]

            for beta in range(0, 3):
                j = local_to_global[r, beta]

                K_h[i, j] = K_h[i, j] + K_r[alpha, beta]

    #neumann boundarys
    #neumann = {"e2g": edge_to_global, "e2n": edge_to_number, "e2l": edge_to_local, "funcs":func_dict}
    edge_to_global = neumann["e2g"]
    edge_to_number = neumann["e2n"]
    edge_to_local = neumann["e2l"]
    func_dict = neumann["funcs"]

    Ne = edge_to_local.shape[1]

    for e in range(0, edge_to_global.shape[0]):
        #only if e in neumann boundary TODO
        #print(func_dict.keys())

        if edge_to_number[e] in func_dict.keys():

            e_number = edge_to_number[e]

            #create fe2
            fe2 = np.zeros(shape=(Ne, 1))

            xe_1 = nodes_to_coordinates[edge_to_global[e, 0], 0]
            xe_Ne = nodes_to_coordinates[edge_to_global[e, Ne - 1], 0]
            ye_1 = nodes_to_coordinates[edge_to_global[e, 0], 1]
            ye_Ne = nodes_to_coordinates[edge_to_global[e, Ne - 1], 1]

            root = math.sqrt((xe_Ne - xe_1)**2 + (ye_Ne - ye_1)**2)

            #x = (xe_Ne - xe_1) + xi1 + xe_1
            #y = (ye_Ne - ye_1) + xi2 + ye_1
            x_e = lambda xi: (xe_Ne - xe_1) + xi + xe_1
            y_e = lambda xi: (ye_Ne - ye_1) + xi + ye_1

            #phi_lin_tri

            #int func(global_to_ref(xi)) phi_(p,e) root ds

            l1 = int(edge_to_local[e, 0])
            l2 = int(edge_to_local[e, 1])

            #do this with for loop
            fe2[0, 0] = numeric.gauss_1D_6(lambda xi: func_dict[e_number](x_e(
                xi), y_e(xi)) * phi_lin_tri[l1](x_e(xi), y_e(xi)) * root)
            fe2[1, 0] = numeric.gauss_1D_6(lambda xi: func_dict[e_number](x_e(
                xi), y_e(xi)) * phi_lin_tri[l2](x_e(xi), y_e(xi)) * root)

            for p in range(0, Ne):
                i = edge_to_global[e, p]
                f_h[i, 0] = f_h[i, 0] + fe2[p, 0]

    #dirichlet boundarys
    #borders2 = [b[0] for b in borders]
    #borders3 = list(itertools.chain(*borders2))

    values = np.zeros(shape=(N_nodes, 1))
    is_set = np.zeros(shape=(N_nodes, 1))

    for nodes, value in borders:
        for n in nodes:
            is_set[n] = 1
            values[n] = value

    b_tmp = values * is_set

    for i in range(0, N_nodes):
        for j in range(0, N_nodes):
            if is_set[i] == 0:
                f_h[i] = f_h[i] - K_h[i, j] * b_tmp[j]

    for i in range(0, N_nodes):
        for j in range(0, N_nodes):
            if is_set[i] == 1 or is_set[j] == 1:
                if i == j:
                    K_h[i, j] = 1
                else:
                    K_h[i, j] = 0

        if is_set[i] == 1:
            f_h[i] = values[i]

    return K_h, f_h
Ejemplo n.º 4
0
def assemble_equations(local_to_global, nodes_to_coordinates, borders, eps, rho, neumann):
    """
    Assembles the final system of linear equations to be solved.
    Outputs a Matrix K_h and the right hand side vector f_h
    """

    N_nodes = nodes_to_coordinates.shape[0]
    N_fe = local_to_global.shape[0]

    K_h = np.zeros(shape=(N_nodes, N_nodes))
    f_h = np.zeros(shape=(N_nodes,1))

    for r in range(0, N_fe):
        
        #K_r, f_r for each element
        i1 = local_to_global[r, 0]
        i2 = local_to_global[r, 1]
        i3 = local_to_global[r, 2]
        x1 = nodes_to_coordinates[i1, 0] 
        x2 = nodes_to_coordinates[i2, 0] 
        x3 = nodes_to_coordinates[i3, 0] 
        y1 = nodes_to_coordinates[i1, 1] 
        y2 = nodes_to_coordinates[i2, 1] 
        y3 = nodes_to_coordinates[i3, 1] 

        K_r = _calculate_K_r(x1, x2, x3, y1, y2, y3, eps)
        f_r = _calculate_f_r(x1, x2, x3, y1, y2, y3, rho) 

        for alpha in range(0,3):
            i = local_to_global[r,alpha]
            
            f_h[i,0] = f_h[i,0] + f_r[alpha,0]
            
            for beta in range(0,3):
                j = local_to_global[r,beta]

                K_h[i,j] = K_h[i,j] + K_r[alpha,beta] 

    #neumann boundarys
    #neumann = {"e2g": edge_to_global, "e2n": edge_to_number, "e2l": edge_to_local, "funcs":func_dict} 
    edge_to_global = neumann["e2g"]
    edge_to_number = neumann["e2n"]
    edge_to_local = neumann["e2l"]
    func_dict = neumann["funcs"]

    Ne = edge_to_local.shape[1]

    for e in range(0, edge_to_global.shape[0]):
        #only if e in neumann boundary TODO
        #print(func_dict.keys())
        
        if edge_to_number[e] in func_dict.keys():

            e_number = edge_to_number[e]

            #create fe2
            fe2 = np.zeros(shape=(Ne,1))
            
            xe_1 = nodes_to_coordinates[edge_to_global[e, 0], 0]
            xe_Ne = nodes_to_coordinates[edge_to_global[e, Ne-1], 0]
            ye_1 = nodes_to_coordinates[edge_to_global[e, 0], 1]
            ye_Ne = nodes_to_coordinates[edge_to_global[e, Ne-1], 1]

            root =  math.sqrt( (xe_Ne-xe_1)**2 + (ye_Ne-ye_1)**2 )

            #x = (xe_Ne - xe_1) + xi1 + xe_1
            #y = (ye_Ne - ye_1) + xi2 + ye_1
            x_e = lambda xi: (xe_Ne - xe_1) + xi + xe_1
            y_e = lambda xi: (ye_Ne - ye_1) + xi + ye_1

            #phi_lin_tri

            #int func(global_to_ref(xi)) phi_(p,e) root ds

            l1 = int(edge_to_local[e,0])
            l2 = int(edge_to_local[e,1])

            
            #do this with for loop
            fe2[0,0] = numeric.gauss_1D_6( lambda xi: func_dict[e_number](x_e(xi), y_e(xi)) * phi_lin_tri[l1](x_e(xi), y_e(xi)) * root )
            fe2[1,0] = numeric.gauss_1D_6( lambda xi: func_dict[e_number](x_e(xi), y_e(xi)) * phi_lin_tri[l2](x_e(xi), y_e(xi)) * root )

            for p in range(0, Ne):
                i = edge_to_global[e,p]
                f_h[i,0] = f_h[i,0] + fe2[p,0]



    #dirichlet boundarys
    #borders2 = [b[0] for b in borders]
    #borders3 = list(itertools.chain(*borders2))

    values = np.zeros(shape=(N_nodes,1))
    is_set = np.zeros(shape=(N_nodes,1))
    
    for nodes, value in borders:
        for n in nodes:
           is_set[n] = 1
           values[n] = value

    b_tmp = values * is_set

    for i in range(0, N_nodes):
        for j in range(0, N_nodes):
            if is_set[i] == 0:
                f_h[i] = f_h[i] - K_h[i,j] * b_tmp[j]

    for i in range(0,N_nodes):
        for j in range(0,N_nodes):
            if is_set[i] == 1 or is_set[j] == 1:
                if i == j:
                    K_h[i,j] = 1
                else:
                    K_h[i,j] = 0

        if is_set[i] == 1:
            f_h[i] = values[i]

    return K_h, f_h