예제 #1
0
    def showElementValues(self):
        if self.calcDone == True:
            self.elValueFig = cfv.figure(self.elValueFig)
            cfv.drawElementValues(self.outputData.vonMises,
                                  self.outputData.coords,
                                  self.outputData.edof,
                                  self.outputData.dofsPerNode,
                                  self.outputData.elType,
                                  self.outputData.asolve,
                                  doDrawMesh=True,
                                  doDrawUndisplacedMesh=False,
                                  title="Effective Stress",
                                  magnfac=25.0)

            cfv.colorBar().SetLabel("Effective stress")

            cfu.info("Done drawing...")
예제 #2
0
    def updateMesh(self):
        """Update mesh"""

        cfu.info("Meshing geometry...")

        # 3 Quads

        self.elType = 3
        self.dofsPerNode = 2

        # Create mesh

        self.mesh = cfm.GmshMeshGenerator(geometry=self.g)
        self.mesh.elType = self.elType
        self.mesh.dofsPerNode = self.dofsPerNode

        self.coords, self.edof, self.dofs, self.bdofs, self.elementmarkers = self.mesh.create(
        )
예제 #3
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]))
예제 #4
0
    def updateGeometry(self):
        """Update geometry"""

        cfu.info("Creating geometry...")

        self.g = cfg.geometry()
        g = self.g

        # Just a shorthand. We use this to make the circle arcs.

        s2 = 1 / sqrt(2)

        points = [
            [0, 3],
            [2.5, 3],
            [3, 3],
            [4 - s2, 3 - s2],
            [4, 2],  #0-4
            [4 + s2, 3 - s2],
            [5, 3],
            [5.5, 3],
            [8, 3],
            [0, 1.5],  #5-9
            [2.5, 1.5],
            [4, 1.5],
            [5.5, 1.5],
            [8, 1.5],
            [0, 0],  #10-14
            [2.5, 0],
            [3, 0],
            [4 - s2, s2],
            [4, 1],
            [4 + s2, s2],  #15-19
            [5, 0],
            [5.5, 0],
            [8, 0],
            [4, 3],
            [4, 0]
        ]  #20-24

        for xp, yp in points:
            g.point([xp * 0.1, yp * 0.1])

        splines = [
            [0, 1],
            [1, 2],
            [6, 7],
            [7, 8],
            [8, 13],  #0-4
            [13, 22],
            [22, 21],
            [21, 20],
            [16, 15],
            [15, 14],  #5-9
            [14, 9],
            [9, 0],
            [9, 10],
            [10, 1],
            [10, 15],  #10-14
            [10, 11],
            [11, 4],
            [11, 18],
            [11, 12],
            [12, 7],  #15-19
            [12, 21],
            [12, 13],
            [3, 10],
            [5, 12],
            [10, 17],  #20-24
            [12, 19]
        ]  #25

        for s in splines:
            g.spline(s, elOnCurve=5)

        g.curveMarker(ID=4,
                      marker=7)  #Assign marker 7 to the splines on the right.
        g.curveMarker(
            ID=5, marker=7)  # We will apply a force on nodes with marker 7.
        g.curveMarker(ID=10,
                      marker=5)  #Assign marker 5 to the splines on the left.
        g.curveMarker(
            ID=11,
            marker=5)  # The nodes with marker 5 will be locked in place.

        # Points in circle arcs are [start, center, end]

        circlearcs = [
            [2, 23, 3],
            [3, 23, 4],
            [4, 23, 5],
            [5, 23, 6],  #26-29
            [16, 24, 17],
            [17, 24, 18],
            [18, 24, 19],
            [19, 24, 20]
        ]  #30-33

        for c in circlearcs:
            g.circle(c, elOnCurve=5)

        g.structuredSurface([11, 12, 13, 0])  #0
        g.structuredSurface([14, 12, 10, 9])
        g.structuredSurface([8, 30, 24, 14])
        g.structuredSurface([24, 31, 17, 15])
        g.structuredSurface([15, 16, 27, 22])  #4
        g.structuredSurface([22, 26, 1, 13])
        g.structuredSurface([16, 18, 23, 28])
        g.structuredSurface([19, 2, 29, 23])
        g.structuredSurface([19, 21, 4, 3])  #8
        g.structuredSurface([20, 6, 5, 21])
        g.structuredSurface([25, 20, 7, 33])
        g.structuredSurface([32, 17, 18, 25])  #11
예제 #5
0
The example does not contain anything that is not covered in the previous examples.
'''

import calfem.core as cfc
import calfem.vis as cfv
import calfem.utils as cfu
import calfem.shapes as cfs
import calfem.solver as cfslv

cfu.enableLogging()

# ---- General parameters ---------------------------------------------------

# Define marker constants instead of using numbers in the code

cfu.info("Creating rectangle")

rect = cfs.Rectangle(5.0, 1.0, elementType=3, dofsPerNode=2, maxArea=0.08)
rect.t = 0.2
rect.v = 0.35
rect.E = 2e9
rect.ptype = 1
rect.ep = [rect.ptype, rect.t]
rect.D = cfc.hooke(rect.ptype, rect.E, rect.v)

cfu.info("Creating mesh...")

mesh = cfs.ShapeMesh(rect)

# ---- Solve problem --------------------------------------------------------
예제 #6
0
from math import sqrt

cfu.enableLogging()

# ---- Define problem variables ---------------------------------------------

t = 0.2
v = 0.35
E = 2.1e9
ptype = 1
ep = [ptype, t]
D = cfc.hooke(ptype, E, v)

# ---- Define geometry ------------------------------------------------------

cfu.info("Creating geometry...")

g = cfg.geometry()

# Just a shorthand. We use this to make the circle arcs.

s2 = 1 / sqrt(2)

points = [
    [0, 3],
    [2.5, 3],
    [3, 3],
    [4 - s2, 3 - s2],
    [4, 2],  #0-4
    [4 + s2, 3 - s2],
    [5, 3],
예제 #7
0
mesh.dofs_per_node = dofs_per_node

# Mesh the geometry:
#  The first four return values are the same as those that trimesh2d() returns.
#  value elementmarkers is a list of markers, and is used for finding the 
#  marker of a given element (index).

coords, edof, dofs, bdofs, elementmarkers = mesh.create()

# ---- Solve problem --------------------------------------------------------

nDofs = np.size(dofs)
K = lil_matrix((nDofs,nDofs))
ex, ey = cfc.coordxtr(edof, coords, dofs)

cfu.info("Assembling K... ("+str(nDofs)+")")

for eltopo, elx, ely, elMarker in zip(edof, ex, ey, elementmarkers):

    if el_type == 2:
        Ke = cfc.plante(elx, ely, elprop[elMarker][0], elprop[elMarker][1])
    else:
        Ke = cfc.planqe(elx, ely, elprop[elMarker][0], elprop[elMarker][1])
        
    cfc.assem(eltopo, K, Ke)
    
cfu.info("Applying bc and loads...")

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