Exemplo n.º 1
0
def giveElemVolume(elem, elemType):
    mat_id = elem["MaterialId"] - 1
    material = globalvars.data["Materials"][mat_id]
    if (elemType == "BR02" or elemType == "TRUSS02"):
        area = material["Area"]
        node1 = elem["Connectivities"][0] - 1
        x1 = globalvars.data["Mesh"]["Nodes"][node1]["x"]
        y1 = globalvars.data["Mesh"]["Nodes"][node1]["y"]
        node2 = elem["Connectivities"][1] - 1
        x2 = globalvars.data["Mesh"]["Nodes"][node2]["x"]
        y2 = globalvars.data["Mesh"]["Nodes"][node2]["y"]
        length = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
        volume = area * length
    elif (elemType == "TR03" or elemType == "QU04"):
        thickness = 1.0
        if (material["Plane_Type"] == "Plane_Stress"):
            thickness = material["Thickness"]
        ngauss = Set_Ngauss(elemType)
        Nodes = globalvars.data["Mesh"]["Nodes"]
        pos_pg, W = GaussQuadrature(elemType)
        area = 0.0
        for igauss in range(ngauss):
            det_Jac, _ = derivCartesian(elem, elemType, Nodes, pos_pg[igauss])
            area += det_Jac * W[igauss]
        volume = area * thickness
    return volume
Exemplo n.º 2
0
def CalcMassMatrix(ElemType, elem):
    nnodes = GiveNnodes(ElemType)
    ngauss = Set_Ngauss(ElemType)
    mat_id = elem["MaterialId"] - 1
    material = globalvars.data["Materials"][mat_id]
    Nodes = globalvars.data["Mesh"]["Nodes"]
    pos_pg, W = GaussQuadrature(ElemType)

    if (globalvars.data["ProblemType"] == "Thermal"):
        rho = material["Specific_Heat"]
        nrows = nnodes
        ncols = nnodes
        ngl = 1
    elif (globalvars.data["ProblemType"] == "Structural_Mechanics"):
        rho = material["Density"]
        if (ElemType == "BAR02"):
            nrows = nnodes
            ncols = nnodes
            ngl = 1
        else:
            nrows = nnodes * 2
            ncols = nnodes * 2
            ngl = 2

        if (ElemType == "BAR02" or ElemType == "TRUSS02"):
            rho *= material["Area"]
        elif (ElemType == "TR03" or ElemType == "TR06" or ElemType == "QU04"
              or ElemType == "QU08" or ElemType == "QU09"):
            thickness = 1.0
            if (material["Plane_Type"] == "Plane_Stress"):
                thickness = material["Thickness"]
            rho *= thickness

    massMatrix = np.zeros((nrows, ncols), dtype=float)
    localMat = np.zeros((ngl, ngl), dtype=float)
    massMatrix_pg = np.zeros((ngl, ngl), dtype=float)

    for inode in range(nnodes):
        for jnode in range(nnodes):
            irow_ini = inode * ngl
            irow_end = irow_ini + ngl
            icol_ini = jnode * ngl
            icol_end = icol_ini + ngl
            for igauss in range(ngauss):
                fform = FuncForm(ElemType, pos_pg, igauss)
                for igl in range(ngl):
                    localMat[igl, igl] = fform[inode] * fform[jnode]
                det_Jac, _ = derivCartesian(elem, ElemType, Nodes,
                                            pos_pg[igauss])
                massMatrix_pg[:ngl, :ngl] = localMat[:ngl, :ngl] * rho * W[
                    igauss] * det_Jac
                massMatrix[irow_ini:irow_end,
                           icol_ini:icol_end] += massMatrix_pg[:ngl, :ngl]

    return massMatrix
Exemplo n.º 3
0
def Smooth_Forces():
    num_nodes = len(globalvars.data["Mesh"]["Nodes"])
    nodal_Forces = np.zeros((num_nodes, 3), dtype=float)
    node_counter = np.zeros((num_nodes), dtype=int)
    ProblemType = globalvars.data["ProblemType"]
    ElemType = globalvars.data["Mesh"]["ElemType"]
    nnode = GiveNnodes(ElemType)
    ngauss = Set_Ngauss(ElemType)
    ncomp = GiveNComp(ElemType, ProblemType)
    Eps_vec = np.zeros((ncomp, ngauss), dtype=float)
    Sigma_vec = np.zeros((ncomp, ngauss), dtype=float)
    Forces_vec = np.zeros((ncomp, ngauss), dtype=float)
    ielem = 0
    for elem in globalvars.data["Mesh"]["Elements"]:
        mat_id = elem["MaterialId"] - 1
        material = globalvars.data["Materials"][mat_id]
        factor = 1.0
        if (ElemType == "TR03" or ElemType == "TR06" or ElemType == "QU04"
                or ElemType == "QU08" or ElemType == "QU09"):
            if (material["Plane_Type"] == "Plane_Stress"):
                factor = material["Thickness"]
        elif (ElemType == "TRUSS02" or ElemType == "BAR02"
              or ElemType == "BAR03"):
            factor = material["Area"]
        if (ElemType == "TR03"):
            Sigma_vec_TR03 = Stress_TR03(elem)
            Forces_vec[:ncomp, :] = Sigma_vec_TR03[:ncomp] * factor
        else:
            for igauss in range(ngauss):
                if (len(globalvars.Sigma_elem_vec[0]) == 0):
                    Eps_vec[:, igauss] = Strain_Solid(elem, ElemType,
                                                      ProblemType, igauss)
                    Sigma_vec[:,
                              igauss] = Stress_Solid(elem, ElemType,
                                                     Eps_vec[:, igauss])
                else:
                    for icomp in range(ncomp):
                        Sigma_vec[icomp,
                                  igauss] = globalvars.Sigma_elem_vec[icomp][
                                      ielem, igauss]
                Forces_vec[:, igauss] = Sigma_vec[:, igauss] * factor
        ielem += 1

        for inode in range(nnode):
            id_node = elem["Connectivities"][inode] - 1
            node_counter[id_node] += 1
            nodal_Forces[id_node, :ncomp] += Forces_vec[:ncomp, inode]

    for inode in range(num_nodes):
        nodal_Forces[inode, :ncomp] /= node_counter[inode]

    return nodal_Forces
Exemplo n.º 4
0
def Smooth_Stresses():
    num_nodes = len(globalvars.data["Mesh"]["Nodes"])
    nodal_Sigma = np.zeros((num_nodes, 3), dtype=float)
    node_counter = np.zeros((num_nodes), dtype=int)
    ProblemType = globalvars.data["ProblemType"]
    ElemType = globalvars.data["Mesh"]["ElemType"]
    nnode = GiveNnodes(ElemType)
    ngauss = Set_Ngauss(ElemType)
    ncomp = GiveNComp(ElemType, ProblemType)
    Eps_vec = np.zeros((ncomp, ngauss), dtype=float)
    Sigma_vec = np.zeros((ncomp, ngauss), dtype=float)
    num_elems = len(globalvars.data["Mesh"]["Elements"])
    for icomp in range(ncomp):
        globalvars.Sigma_elem_vec[icomp] = np.zeros((num_elems, ngauss),
                                                    dtype=float)
    ielem = 0
    for elem in globalvars.data["Mesh"]["Elements"]:
        if (ElemType == "TR03"):
            Sigma_vec_TR03 = Stress_TR03(elem)
            for igauss in range(ngauss):
                Sigma_vec[:ncomp, igauss] = Sigma_vec_TR03[:ncomp]
        else:
            for igauss in range(ngauss):
                if (len(globalvars.Eps_elem_vec[0]) == 0):
                    Eps_vec[:, igauss] = Strain_Solid(elem, ElemType,
                                                      ProblemType, igauss)
                else:
                    for icomp in range(ncomp):
                        Eps_vec[icomp,
                                igauss] = globalvars.Eps_elem_vec[icomp][
                                    ielem, igauss]
                Sigma_vec[:, igauss] = Stress_Solid(elem, ElemType,
                                                    Eps_vec[:, igauss])

        for igauss in range(ngauss):
            for icomp in range(ncomp):
                globalvars.Sigma_elem_vec[icomp][ielem,
                                                 igauss] = Sigma_vec[icomp,
                                                                     igauss]
        ielem += 1

        for inode in range(nnode):
            id_node = elem["Connectivities"][inode] - 1
            node_counter[id_node] += 1
            nodal_Sigma[id_node, :ncomp] += Sigma_vec[:ncomp, inode]

    for inode in range(num_nodes):
        nodal_Sigma[inode, :ncomp] /= node_counter[inode]

    return nodal_Sigma
Exemplo n.º 5
0
def stiffnessMatCalc(elem, ElemType, ProblemType, Dmat):
    ngauss = Set_Ngauss(ElemType)
    Nodes = globalvars.data["Mesh"]["Nodes"]
    ndof = GiveNdof(ElemType, ProblemType)
    nnodes = GiveNnodes(ElemType)
    size = nnodes * ndof
    rigimat = np.zeros((size,size), dtype=float)
    pos_pg, W = GaussQuadrature(ElemType)

    for igauss in range(ngauss):
        det_Jac, derivCart = derivCartesian(elem, ElemType, Nodes, pos_pg[igauss])
        Bmat = Calc_Bmat(ElemType, derivCart, ProblemType)
        DxBmat = np.matmul(Dmat, Bmat)
        rigimat_pg = np.matmul(Bmat.transpose(), DxBmat) * det_Jac * W[igauss]
        rigimat += rigimat_pg
    return rigimat