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_F(S, Coords):
    E = Element("Q4")
    N = E.N()
    G_map = E.G_map()
    F = np.zeros((len(Coords), 1))
    #print(F)
    x_ip = [-np.sqrt(3) / 3, np.sqrt(3) / 3]
    W_ip = [1, 1]
    for i in range(len(x_ip)):

        N_l = N(x_ip[i], x_ip[i])  #N local
        N_T = np.transpose(N_l)
        B, Jdet = G_map(x_ip[i], x_ip[i], Coords)
        #print("N_T is ",N_T)
        S_val = S(x_ip[i], x_ip[i])
        #print(S_val)
        F = F + N_T * S_val * Jdet * W_ip[i] * W_ip[i]
        #print(F)
    #reference file
    file = open('../outputs/f_elemental.txt', 'w')
    for i in range(4):
        if i != 0:
            file.write('\n')
        file.write(str(F[i]))
        file.write(" ")
    file.close()
    return F
Esempio n. 3
0
def MatrixS3D(Coords, n, Coefficients, el_type, Upwinded):
    E = Element(el_type)
    Se = np.zeros((len(Coords), len(Coords)))
    x_ip = [-np.sqrt(3) / 3, np.sqrt(3) / 3]
    weights = [1, 1]
    x_0 = Coefficients[6]
    r_c = Coefficients[4]
    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, G, J_inv = E.G_ext(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
                sigma = Coefficients[3](x_coord, y_coord, z_coord, r_c, x_0)
                Se += -N_T * (
                    sigma) * N * Jdet * weights[i] * weights[j] * weights[k]
                if Upwinded == True:
                    delta = CalcDelta3D(Coefficients,
                                        [x_coord, y_coord, z_coord], n)
                    Se += -delta * np.dot(
                        B_T, n.transpose()
                    ) * sigma * N * Jdet * weights[i] * weights[j] * weights[k]
    return Se
Esempio n. 4
0
def F_GRAV(trac):
    f_grav = np.zeros((8, 1))
    E = Element("Q4")

    weights = [1, 1]
    xIP = [-np.sqrt(3) / 3, np.sqrt(3) / 3]
    for k in range(len(xIP)):
        s = xIP[k]
        N = E.N(s, s)
        J_s = np.matrix(detJsideQ4(s, s))
        n_mat = np.matrix(N.transpose())
        trac_mat = np.matrix(trac)
        f_grav += n_mat * trac_mat * J_s[0, k] * weights[k]
    return f_grav
Esempio n. 5
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. 6
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. 7
0
def MatrixT2D(Coords, n, Coefficients, el_type, Upwinded):
    E = Element(el_type)
    Te = np.zeros((len(Coords), len(Coords)))
    x_ip = [-np.sqrt(3) / 3, np.sqrt(3) / 3]
    weights = [1, 1]
    for i in range(len(x_ip)):
        for j in range(len(x_ip)):
            N = E.N(x_ip[i], x_ip[j], 0)
            N_T = N.transpose()
            B, Jdet, G, J_inv = E.G_ext(x_ip[i], x_ip[j], 0, Coords)
            B_T = B.transpose()
            Te += N_T * np.dot(n, B) * Jdet * weights[i] * weights[j]
            if Upwinded == True:
                x_coord = np.array([Coords[:, 0]]) @ N.transpose()
                y_coord = np.array([Coords[:, 1]]) @ N.transpose()
                delta = CalcDelta2D(Coefficients, [x_coord, y_coord], n)
                Te += delta * np.dot(B_T, n.transpose()) * np.dot(
                    n, B) * Jdet * weights[i] * weights[j]
    return Te
Esempio n. 8
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
Esempio n. 9
0
def MatrixK2D(Coords, n, Coefficients, el_type, Upwinded):
    E = Element(el_type)
    Ke = np.zeros((len(Coords), len(Coords)))
    x_ip = [-np.sqrt(3) / 3, np.sqrt(3) / 3]
    weights = [1, 1]
    for i in range(len(x_ip)):
        for j in range(len(x_ip)):
            N = E.N(x_ip[i], x_ip[j], 0)
            N_T = N.transpose()
            B, Jdet, G, J_inv = E.G_ext(x_ip[i], x_ip[j], 0, Coords)
            B_T = B.transpose()
            x_coord = np.array([Coords[:, 0]]) @ N_T
            y_coord = np.array([Coords[:, 1]]) @ N_T
            kappa_and_sigma = (Coefficients[0](x_coord, y_coord) +
                               Coefficients[3](x_coord, y_coord))
            Ke += N_T * (kappa_and_sigma) * N * Jdet * weights[i] * weights[j]
            if Upwinded == True:
                delta = CalcDelta2D(Coefficients, [x_coord, y_coord], n)
                Ke += delta * np.dot(B_T, n.transpose(
                )) * kappa_and_sigma * N * Jdet * weights[i] * weights[j]
    return Ke