Beispiel #1
0
    def solve(self):
        """Solve problem"""

        self.updateGeometry()
        self.updateMesh()

        self.ep = [self.ptype, self.t]
        self.D = cfc.hooke(self.ptype, self.E, self.v)

        cfu.info("Assembling system matrix...")

        nDofs = np.size(self.dofs)
        ex, ey = cfc.coordxtr(self.edof, self.coords, self.dofs)
        K = np.zeros([nDofs, nDofs])

        for eltopo, elx, ely in zip(self.edof, ex, ey):
            Ke = cfc.planqe(elx, ely, self.ep, self.D)
            cfc.assem(eltopo, K, Ke)

        cfu.info("Solving equation system...")

        f = np.zeros([nDofs, 1])

        bc = np.array([], 'i')
        bcVal = np.array([], 'i')

        bc, bcVal = cfu.applybc(self.bdofs, bc, bcVal, 5, 0.0, 0)

        cfu.applyforce(self.bdofs, f, 7, 10e5, 1)

        self.a, self.r = cfc.solveq(K, f, bc, bcVal)

        cfu.info("Computing element forces...")

        ed = cfc.extractEldisp(self.edof, self.a)
        self.vonMises = []

        # For each element:

        for i in range(self.edof.shape[0]):

            # Determine element stresses and strains in the element.

            es, et = cfc.planqs(ex[i, :], ey[i, :], self.ep, self.D, ed[i, :])

            # Calc and append effective stress to list.

            self.vonMises.append(
                sqrt(
                    pow(es[0], 2) - es[0] * es[1] + pow(es[1], 2) + 3 * es[2]))
    def on_calc_el_force(self, ex, ey, ed, element_type):
        if element_type == 2:
            es, et = cfc.plants(ex, ey, self.mesh.shape.ep, self.mesh.shape.D,
                                ed)
            elMises = np.math.sqrt(
                pow(es[0, 0], 2) - es[0, 0] * es[0, 1] + pow(es[0, 1], 2) +
                3 * pow(es[0, 2], 2))
        else:
            es, et = cfc.planqs(ex, ey, self.mesh.shape.ep, self.mesh.shape.D,
                                ed)
            elMises = np.math.sqrt(
                pow(es[0], 2) - es[0] * es[1] + pow(es[1], 2) +
                3 * pow(es[2], 2))

        return elMises
Beispiel #3
0
bcVal = np.array([], 'f')

bc, bcVal = cfu.applybc(bdofs, bc, bcVal, left_support, 0.0, 0)
bc, bcVal = cfu.applybc(bdofs, bc, bcVal, right_support, 0.0, 2)

f = np.zeros([nDofs, 1])

cfu.applyforcetotal(bdofs, f, top_line, -10e5, 2)

a, r = cfc.solveq(K, f, bc, bcVal)

ed = cfc.extractEldisp(edof, a)
vonMises = []

for i in range(edof.shape[0]):
    es, et = cfc.planqs(ex[i, :], ey[i, :], ep, D, ed[i, :])
    vonMises.append(
        sqrt(pow(es[0], 2) - es[0] * es[1] + pow(es[1], 2) + 3 * es[2]))

# ----- Draw geometry

cfv.drawGeometry(g)

# ----- Draw the mesh.

cfv.figure()
cfv.drawMesh(coords=coords,
             edof=edof,
             dofsPerNode=mesh.dofsPerNode,
             elType=mesh.elType,
             filled=True,
Beispiel #4
0
    # Handle triangle elements
        
    if elType == 2: 
        es, et = cfc.plants(ex[i,:], ey[i,:], 
                        elprop[elementmarkers[i]][0], 
                        elprop[elementmarkers[i]][1], 
                        ed[i,:])
        
        vonMises.append( np.math.sqrt( pow(es[0,0],2) - es[0,0]*es[0,1] + pow(es[0,1],2) + 3*pow(es[0,2],2) ) )

    else:
        
        # Handle quad elements
        
        es, et = cfc.planqs(ex[i,:], ey[i,:], 
                        elprop[elementmarkers[i]][0], 
                        elprop[elementmarkers[i]][1], 
                        ed[i,:])
        
        vonMises.append( np.math.sqrt( pow(es[0],2) - es[0]*es[1] + pow(es[1],2) + 3*pow(es[2],2) ) )
        
# ---- Visualise results ----------------------------------------------------

print("Drawing results...")

cfv.figure() 
cfv.drawGeometry(g, title="Geometry")

cfv.figure() 
cfv.drawMesh(coords=coords, edof=edof, dofsPerNode=dofsPerNode, elType=elType, 
             filled=True, title="Mesh") #Draws the mesh.
Beispiel #5
0
    # Handle triangle elements
        
    if el_type == 2: 
        es, et = cfc.plants(ex[i,:], ey[i,:], 
                        elprop[elementmarkers[i]][0], 
                        elprop[elementmarkers[i]][1], 
                        ed[i,:])
        
        von_mises.append( np.math.sqrt( pow(es[0,0],2) - es[0,0]*es[0,1] + pow(es[0,1],2) + 3*pow(es[0,2],2) ) )

    else:
        
        # Handle quad elements
        
        es, et = cfc.planqs(ex[i,:], ey[i,:], 
                        elprop[elementmarkers[i]][0], 
                        elprop[elementmarkers[i]][1], 
                        ed[i,:])
        
        von_mises.append( np.math.sqrt( pow(es[0],2) - es[0]*es[1] + pow(es[1],2) + 3*pow(es[2],2) ) )
        
# ---- Visualise results ----------------------------------------------------

cfu.info("Drawing results...")

cfv.figure() 
cfv.draw_geometry(g, title="Geometry")

cfv.figure() 
cfv.draw_mesh(coords=coords, edof=edof, dofs_per_node=dofs_per_node, el_type=el_type, 
             filled=True, title="Mesh") #Draws the mesh.
Beispiel #6
0
    def execute(self):

        # --- Överför modell variabler till lokala referenser

        ep = self.inputData.ep
        E = self.inputData.E
        v = self.inputData.v
        Elementsize = self.inputData.Elementsize

        # --- Anropa InputData för en geomtetribeskrivning

        geometry = self.inputData.geometry()

        # --- Nätgenerering

        elType = 3  # <-- Fyrnodselement flw2i4e
        dofsPerNode = 2

        meshGen = cfm.GmshMeshGenerator(geometry)

        meshGen.elSizeFactor = Elementsize  # <-- Anger max area för element
        meshGen.elType = elType
        meshGen.dofsPerNode = dofsPerNode
        meshGen.returnBoundaryElements = True

        coords, edof, dof, bdofs, elementmarkers, boundaryElements = meshGen.create(
        )
        self.outputData.topo = meshGen.topo

        #Solver
        bc = np.array([], 'i')
        bcVal = np.array([], 'i')

        D = cfc.hooke(1, E, v)
        nDofs = np.size(dof)
        ex, ey = cfc.coordxtr(edof, coords, dof)  #Coordinates
        K = np.zeros([nDofs, nDofs])

        #Append Boundary Conds
        f = np.zeros([nDofs, 1])
        bc, bcVal = cfu.applybc(bdofs, bc, bcVal, 30, 0.0, 0)
        cfu.applyforce(bdofs, f, 20, 100e3, 1)

        qs_array = []
        qt_array = []

        for x, y, z in zip(ex, ey, edof):

            Ke = cfc.planqe(x, y, ep, D)

            cfc.assem(z, K, Ke)

        asolve, r = cfc.solveq(K, f, bc, bcVal)

        ed = cfc.extractEldisp(edof, asolve)
        for x, y, z in zip(ex, ey, ed):
            qs, qt = cfc.planqs(x, y, ep, D, z)

            qs_array.append(qs)
            qt_array.append(qt)

        vonMises = []
        stresses1 = []
        stresses2 = []
        # For each element:

        for i in range(edof.shape[0]):

            # Determine element stresses and strains in the element.

            es, et = cfc.planqs(ex[i, :], ey[i, :], ep, D, ed[i, :])

            # Calc and append effective stress to list.

            vonMises.append(
                np.sqrt(
                    pow(es[0], 2) - es[0] * es[1] + pow(es[1], 2) + 3 * es[2]))

            ## es: [sigx sigy tauxy]
            # sigmaij = np.array([[es(i,1),es(i,3),0],[es(i,3),es(i,2),0],[0,0,0]])
            sigmaij = np.array([[es[0], es[2], 0], [es[2], es[1], 0],
                                [0, 0, 0]])
            [v, w] = np.linalg.eig(sigmaij)
            stresses1.append(v[0] * w[0])
            stresses2.append(v[1] * w[1])

        # --- Överför modell variabler till lokala referenser

        self.outputData.vonMises = vonMises
        self.outputData.edof = edof
        self.outputData.coords = coords
        self.outputData.stresses1 = stresses1
        self.outputData.stresses2 = stresses2
        self.outputData.geometry = geometry
        self.outputData.asolve = asolve
        self.outputData.r = r
        self.outputData.ed = ed
        self.outputData.qs = qs_array
        self.outputData.qt = qt_array
        self.outputData.dofsPerNode = dofsPerNode
        self.outputData.elType = elType
        self.outputData.calcDone = True