Esempio n. 1
0
def VectorF3D(Coords, n, Coefficients, sourceFunc, El_type, Upwinded):
    E = Element(El_type)
    weights = [1, 1]
    x_ip = [-np.sqrt(3) / 3, np.sqrt(3) / 3]
    f_ele = np.zeros((len(Coords), 1))
    for i in range(len(x_ip)):
        for j in range(len(x_ip)):
            for k in range(len(x_ip)):
                N = E.N(x_ip[i], x_ip[j], x_ip[k])
                N_T = N.transpose()
                B, Jdet = E.G(x_ip[i], x_ip[j], x_ip[k], Coords)
                B_T = B.transpose()
                x_coord = np.array([Coords[:, 0]]) @ N_T
                y_coord = np.array([Coords[:, 1]]) @ N_T
                z_coord = np.array([Coords[:, 2]]) @ N_T
                source = SourceTerm3D([x_coord, y_coord, z_coord],
                                      Coefficients, sourceFunc)
                f_ele += N_T * source * Jdet * weights[i] * weights[
                    j] * weights[k]
                if Upwinded == True:
                    delta = CalcDelta3D(Coefficients,
                                        [x_coord, y_coord, z_coord], n)
                    f_ele += delta * np.dot(B_T, n.transpose(
                    )) * source * Jdet * weights[i] * weights[j] * weights[k]
    return f_ele
Esempio n. 2
0
def Dif_basic_K(el_type,
                Coords,
                k=1,
                P_type='scalar'):  #let k be an optional arguement
    El = Element(el_type)
    if el_type == 'Q4':
        num_nodes = 4  # number of nodes
    elif el_type == 'Q8':
        num_nodes = 8
    else:
        print('Please enter a valid element type')
    K = np.zeros((num_nodes, num_nodes))
    G = El.G()  # snag B-matrix for element
    if (P_type == 'scalar'
        ):  # calculates B function based on scalar or vector problem!
        B = G
    elif (P_type == 'vector'):
        B = np.zeros((3, 8))
        for i in range(2 * num_nodes):
            B[0, 2 * i] = G[0, i]
            B[1, 2 * i - 1] = G[1, i]
            B[2, 2 * i] = G[0, i]
            B[2, 2 * i - 1] = G[1, i]
    else:
        print('Please enter valid problem type')
    #calculate jacobian determinant  -- take another look at this!!!!!

    J = lambda x, y: np.dot(G(x, y), Coords)
    J_d = lambda x, y: np.linalg.det(J(x, y))

    # K_mat = lambda x, y: np.dot(np.transpose(B(x,y)), k*B(x,y))*abs(Jd_m(x,y)) # Create K_matrix based on definition in scalar problem - heat
    #K_mat = lambda x, y: np.dot(K_mat1(x,y), J(x,y)) ##if mapped element, compute jacobian and tack on
    #print(K_mat(0,0)[0,0])
    # Now to step through K_mat and integrate each element
    Ke = np.zeros((len(Coords), len(Coords)))
    x_ip = [-np.sqrt(3) / 3, np.sqrt(3) / 3]
    w_ip = [1, 1]
    for i in range(len(x_ip)):
        for j in range(len(x_ip)):  # now ready to integrate
            B_val = G(x_ip[i], x_ip[j])
            J_d_val = J_d(x_ip[i], x_ip[j])
            #print(B_val)
            #print(J_d_val)
            Ke = Ke + (np.dot(np.transpose(B_val), k * B_val) * abs(J_d_val) *
                       w_ip[i] * w_ip[j])
    print(Ke)

    file = open('../outputs/K_elemental.txt', 'w')
    for i in range(4):
        if i != 0:
            file.write('\n')
        for j in range(4):
            file.write(str(K[i, j]))
            file.write(" ")
    file.close()
    return Ke
Esempio n. 3
0
def MatrixT(Coords, Coefficients, Upwinded):
    E = Element('S2')
    Ke = np.zeros((2, 2))
    #x_ip = [-np.sqrt(3)/3,np.sqrt(3)/3]
    #weights = [1,1]
    x_ip = [0]
    weights = [2]
    h = (Coords[1][0] - Coords[0][0])
    Jdet = h / 2
    a = Coefficients[0]
    for i in range(len(x_ip)):
        N = E.N(x_ip[i])
        N_T = N.transpose()
        B = E.G(x_ip[i], Coords)
        B_T = B.transpose()
        Ke += a * N_T * B * Jdet * weights[i] + (
            h / 2) * a * B_T * B * Jdet * weights[i]
    return Ke
Esempio n. 4
0
def Dif_basic_F(el_type, S, Coords, P_type='scalar'):
    El = Element('Q4')
    if el_type == 'Q4':
        num_nodes = 4
    elif el_type == 'Q8':
        num_nodes = 8
    else:
        print('Please enter a valid element type')
    G = El.G()  # snag B-matrix for element
    if (P_type == 'scalar'
        ):  # calculates B function based on scalar or vector problem!
        B = G
    elif (P_type == 'vector'):
        B = np.zeros((3, 8))
        for i in range(2 * num_nodes):
            B[0, 2 * i] = G[0, i]
            B[1, 2 * i - 1] = G[1, i]
            B[2, 2 * i] = G[0, i]
            B[2, 2 * i - 1] = G[1, i]
    else:
        print('Please enter valid problem type')
    F = np.zeros(len(Coords))
    N = El.N()  # snag B-matrix for element
    J = lambda x, y: np.dot(G(x, y), Coords)
    J_d = lambda x, y: np.linalg.det(J(x, y))

    x_ip = [-np.sqrt(3) / 3, np.sqrt(3) / 3]
    w_ip = [1, 1]
    for i in range(len(x_ip)):
        N_val = N(x_ip[i], x_ip[i])
        J_d_val = J_d(x_ip[i], x_ip[i])
        S_val = S(x_ip[i], x_ip[i])
        F = F + np.dot(np.transpose(N_val), S_val * J_d_val * w_ip[i])

    #reference file
    file = open('../outputs/f_elemental.txt', 'w')
    for i in range(4):
        if i != 0:
            file.write('\n')
        file.write(str(F[0, i]))
        file.write(" ")
    file.close()
    return F
Esempio n. 5
0
def VectorF(Coords, Coefficients, sourceFunc, Upwinded):
    E = Element("S2")
    #x_ip = [-np.sqrt(3)/3,np.sqrt(3)/3]
    #weights = [1,1]
    x_ip = [0]
    weights = [2]
    f_ele = np.zeros((2, 1))
    h = (Coords[1][0] - Coords[0][0])
    Jdet = h / 2
    a = Coefficients[0]
    for i in range(len(x_ip)):
        N = E.N(x_ip[i])
        N_T = N.transpose()
        B = E.G(x_ip[i], Coords)
        B_T = B.transpose()
        x_coord = np.dot(np.array([Coords[:, 0]]), N.transpose())
        source = SourceTerm(Coords, Coefficients, sourceFunc)
        f_ele += N_T * source * Jdet * weights[
            i]  #+ (h/2)* a * B_T *source * Jdet * weights[i]
    return f_ele