Ejemplo n.º 1
0
 def executeMesh(self):
     """ Utför FE-beräkningen."""
     # --- Överför modellvariabler till lokala referenser
     geometry = self.inputData.geometry()
     elSize = self.inputData.elSize
                  
     
     # --- Skapa mesh
     dofsPerNode = 1
     elType = 2      # <-- Trenodselement 
     meshGen = cfm.GmshMeshGenerator(geometry)
     meshGen.elSizeFactor = elSize
     meshGen.elType = elType
     meshGen.dofsPerNode = dofsPerNode
     coords, edof, dofs, bdofs, elementmarkers = meshGen.create()
     
     # --- Bestäm ex, ey               
     ex, ey = cfc.coordxtr(edof, coords, dofs)        
     
     
     #Returnera framtagen data
     self.outputData.coords = coords  
     self.outputData.edof = edof
     self.outputData.dofs = dofs
     self.outputData.bdofs = bdofs    
     self.outputData.elType = elType
     self.outputData.dofsPerNode = dofsPerNode
     self.outputData.elementmarkers = elementmarkers
     self.outputData.ex = ex
     self.outputData.ey = ey
Ejemplo n.º 2
0
    def create(self):
        meshGen = cfm.GmshMeshGenerator(self.shape.geometry())
        meshGen.elType = self.shape.elementType
        meshGen.elSizeFactor = self.shape.maxArea
        meshGen.dofsPerNode = self.shape.dofsPerNode

        self.coords, self.edof, self.dofs, self.bdofs, self.markers = meshGen.create()

        # --- Beräkna element koordinater

        self.ex, self.ey = cfc.coordxtr(self.edof, self.coords, self.dofs)
        self.pointDofs = self.dofs[list(self.shape.g.points.keys()),:]
Ejemplo n.º 3
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(
        )
Ejemplo n.º 4
0
    def solveProblem(self):

        g = cfg.Geometry()  #Create a GeoData object that holds the geometry.

        g.point([0, 0])
        g.point([2, 0])
        g.point([2, 1])
        g.point([0, 1])
        g.point([0.5, 0.3])
        g.point([0.3, 0.7])
        g.point([0.7, 0.7])
        g.point([0.8, 0.5])
        g.point([1.7, 0.5])
        g.point([1.5, 0.5])
        g.point([1.7, 0.7])

        g.ellipse([7, 8, 9, 10],
                  marker=50)  # 0 - An ellipse arc. Read the function
        g.spline([0, 1], marker=80)  # 1 - A spline. Splines pass through the
        g.spline([2, 1])  # 2
        g.spline([3, 2])  # 3
        g.spline([0, 3])  # 4
        g.spline([7, 9], marker=50)  # 5
        g.spline([10, 9])  # 6
        g.spline([4, 5, 6, 4])  # 7 - This is a closed spline.

        g.surface([4, 3, 2, 1], [[7], [5, 6, 0]])

        meshGen = cfm.GmshMeshGenerator(g)

        meshGen.elType = 3  # Degrees of freedom per node.
        meshGen.dofsPerNode = 1  # Factor that changes element sizes.
        meshGen.elSizeFactor = 0.05

        self.coords, self.edof, self.dofs, self.bdofs, self.elementmarkers = meshGen.create(
        )
        self.meshGen = meshGen
        self.g = g
Ejemplo n.º 5
0
# Element type 16 is 8-node-quad. (See gmsh manual for more element types)

el_type = 16

# Degrees of freedom per node.

dofs_per_node = 1

# ---- Generate mesh --------------------------------------------------------

# gmshExecPath = Path to gmsh.exe.
# If None then the system PATH variable is queried.
# Relative and absolute paths work.

mesh = cfm.GmshMeshGenerator(g, el_type, dofs_per_node)

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

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

print("Assembling system matrix...")

n_dofs = np.size(dofs)
ex, ey = cfc.coordxtr(edof, coords, dofs)

K = np.zeros([n_dofs, n_dofs])

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

    # Calc element stiffness matrix: Conductivity matrix D is taken
Ejemplo n.º 6
0
g.structuredSurface([20, 6, 5, 21])
g.structuredSurface([25, 20, 7, 33])
g.structuredSurface([32, 17, 18, 25])  #11

# ---- Create mesh ----------------------------------------------------------

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

# 3 Quads

elType = 3
dofsPerNode = 2

# Create mesh

meshGen = cfm.GmshMeshGenerator(geometry=g)
meshGen.elType = elType
meshGen.dofsPerNode = dofsPerNode

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

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

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

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

for eltopo, elx, ely in zip(edof, ex, ey):
    Ke = cfc.planqe(elx, ely, ep, D)
Ejemplo n.º 7
0
# The start and end points are the same

# Add a surface:
#  Surfaces are defined by its curve boundaries.
#  The first parameter is a list of curve IDs that specify the outer boundary
#  of the surface. The second parameter is a list of lists of curve IDs that
#  specify holes in the surface. In this example there are two holes. The
#  boundaries and holes must be closed paths. We can see that [7] is closed
#  because curve 7 is a closed spline. addSurface creates a flat surface, so
#  all curves must lie on the same plane.

g.surface([4, 3, 2, 1], [[7], [5, 6, 0]])

# ---- Generate mesh --------------------------------------------------------

meshGen = cfm.GmshMeshGenerator(g)

# Element type 3 is quad.
# (2 is triangle. See user manual for more element types)

meshGen.elType = 2
meshGen.dofsPerNode = 1  # Degrees of freedom per node.
meshGen.elSizeFactor = 0.10  # Factor that changes element sizes.

# Mesh the geometry:
#
# The first four return values are the same as those that trimesh2d() returns.
# coords is as list of node coordinates. edof is the element topology
# (element degrees of freedom). dofs is a lists of all degrees of freedom
# bdofs is a dictionary of boundary dofs (dofs of geometric entities with
# markers). elementmarkers is a list of markers, and is used for finding the
Ejemplo n.º 8
0
# Element type 16 is 8-node-quad. (See gmsh manual for more element types)

elType = 16

#Degrees of freedom per node.

dofsPerNode = 1

# ---- Generate mesh --------------------------------------------------------

# gmshExecPath = Path to gmsh.exe.
# If None then the system PATH variable is queried.
# Relative and absolute paths work.

meshGen = cfm.GmshMeshGenerator(g, elType, dofsPerNode)

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

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

print("Assembling system matrix...")

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

K = np.zeros([nDofs, nDofs])

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

    # Calc element stiffness matrix: Conductivity matrix D is taken
Ejemplo n.º 9
0
    def execute(self):
        # ------ Transfer model variables to local variables
        self.inputData.updateparams()
        version = self.inputData.version
        units = self.inputData.units
        v = self.inputData.v
        ep = self.inputData.ep
        E = self.inputData.E
        mp = self.inputData.mp
        fp = self.inputData.fp
        bp = self.inputData.bp
        ep[1] = ep[1] * U2SI[units][0]
        E = E * U2SI[units][2]
        for i in range(len(fp[0])):
            fp[1][i] = fp[1][i] * U2SI[units][1]
        for i in range(len(bp[0])):
            bp[1][i] = bp[1][i] * U2SI[units][0]

        # Get most updated dxf dimensions and import model geometry to calfem format
        self.inputData.dxf.readDXF(self.inputData.dxf_filename)
        for dim in self.inputData.d:
            ("Adjusting Dimension {0} with val {1}".format(
                dim[0], dim[1] * U2SI[units][0]))
            self.inputData.dxf.adjustDimension(dim[0], dim[1] * U2SI[units][0])
        self.inputData.dxf.adjustDimension(
            self.inputData.c['aName'], self.inputData.c['a'] * U2SI[units][0])
        self.inputData.dxf.adjustDimension(
            self.inputData.c['bName'], self.inputData.c['b'] * U2SI[units][0])
        dxf = self.inputData.dxf

        if self.inputData.refineMesh:
            geometry, curve_dict = dxf.convertToGeometry(max_el_size=mp[2])
        else:
            geometry, curve_dict = dxf.convertToGeometry()

        # Generate the mesh
        meshGen = cfm.GmshMeshGenerator(geometry)
        meshGen.elSizeFactor = mp[2]  # Max Area for elements
        meshGen.elType = mp[0]
        meshGen.dofsPerNode = mp[1]
        meshGen.returnBoundaryElements = True

        coords, edof, dofs, bdofs, elementmarkers, boundaryElements = meshGen.create(
        )

        # Add the force loads and boundary conditions
        bc = np.array([], int)
        bcVal = np.array([], int)
        nDofs = np.size(dofs)
        f = np.zeros([nDofs, 1])

        for i in range(len(bp[0])):
            bc, bcVal = cfu.applybc(bdofs, bc, bcVal, dxf.markers[bp[0][i]],
                                    bp[1][i])
        for i in range(len(fp[0])):
            xforce = fp[1][i] * np.cos(np.radians(fp[2][i]))
            yforce = fp[1][i] * np.sin(np.radians(fp[2][i]))
            cfu.applyforce(bdofs,
                           f,
                           dxf.markers[fp[0][i]],
                           xforce,
                           dimension=1)
            cfu.applyforce(bdofs,
                           f,
                           dxf.markers[fp[0][i]],
                           yforce,
                           dimension=2)

        # ------ Calculate the solution

        print("")
        print("Solving the equation system...")

        # Define the elements coordinates
        ex, ey = cfc.coordxtr(edof, coords, dofs)

        # Define the D and K matrices
        D = (E / (1 - v**2)) * np.matrix([[1, v, 0], [v, 1, 0],
                                          [0, 0, (1 - v) / 2]])
        K = np.zeros([nDofs, nDofs])

        # Extract element coordinates and topology for each element
        for eltopo, elx, ely in zip(edof, ex, ey):
            Ke = cfc.plante(elx, ely, ep, D)
            cfc.assem(eltopo, K, Ke)

        # Solve the system
        a, r = cfc.solveq(K, f, bc, bcVal)

        # ------ Determine stresses and displacements

        print("Computing the element forces")

        # Extract element displacements
        ed = cfc.extractEldisp(edof, a)

        # Determine max displacement
        max_disp = [[0, 0], 0]  # [node idx, value]
        for idx, node in zip(range(len(ed)), ed):
            for i in range(3):
                disp = math.sqrt(node[2 * i]**2 + node[2 * i + 1]**2)
                if disp > max_disp[1]:
                    max_disp = [[idx, 2 * i], disp]

        # Determine Von Mises stresses
        vonMises = []
        max_vm = [0, 0]  # [node idx, value]
        for i in range(edof.shape[0]):
            es, et = cfc.plants(ex[i, :], ey[i, :], ep, D, ed[i, :])
            try:
                vonMises.append(
                    math.sqrt(
                        pow(es[0, 0], 2) - es[0, 0] * es[0, 1] +
                        pow(es[0, 1], 2) + 3 * es[0, 2]))
                if vonMises[-1] > max_vm[1]:
                    max_vm = [i, vonMises[-1]]
            except ValueError:
                vonMises.append(0)
                print("CAUGHT MATH EXCEPTION with es = {0}".format(es))
            # Note: es = [sigx sigy tauxy]

        # ------ Store the solution in the output model variables
        self.outputData.disp = ed
        self.outputData.stress = vonMises
        self.outputData.geometry = geometry
        self.outputData.a = a
        self.outputData.coords = coords
        self.outputData.edof = edof
        self.outputData.mp = mp
        self.outputData.meshGen = meshGen
        self.outputData.statistics = [
            max_vm, max_disp, curve_dict, self.inputData.dxf.anchor,
            self.inputData.dxf.wh
        ]
        if self.inputData.paramFilename is None:
            print("Solution completed.")
Ejemplo n.º 10
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