Ejemplo n.º 1
0
    def on_updateButton_clicked(self):
        """Update preview geo, mesh, stress"""

        self.updateModel()
        warnings = self.inputData.warnings

        #Om det saknas varningar/felmeddelanden:
        if not warnings:
            self.clearfig()

            self.g = fm.InputData.geometry(self.inputData)
            fm.Solver.executeMesh(self)

            #Hämta värden som används vid plot
            q = self.inputData.q
            B = self.inputData.B
            b = self.inputData.b
            hvec = self.inputData.hvec
            coords = self.outputData.coords
            edof = self.outputData.edof
            dofsPerNode = self.outputData.dofsPerNode
            elType = self.outputData.elType
            ndof = edof.max()

            # Bestäm initialspänningarna
            a0 = tg.strdist(coords, ndof, q, B, b, hvec)

            # Figur geometri
            cfv.figure(self.figGeometry.nr)
            cfv.drawGeometry(self.g, title="Geometry")

            # Figur mesh
            cfv.figure(self.figMesh.nr)
            cfv.drawMesh(coords,
                         edof,
                         dofsPerNode,
                         elType,
                         filled=True,
                         title="Mesh")

            # Figur initialspänningar
            cfv.figure(self.figInitial.nr)
            cfv.drawNodalValues(a0,
                                coords,
                                edof,
                                dofsPerNode,
                                elType,
                                clim=(0, self.inputData.q),
                                doDrawMesh=False,
                                title="Initial stress distr.")

            self.tabWidget.setEnabled(True)

        #Om det finns felmeddelanden: visa ej preview utan aktivera felmeddelanden
        else:
            self.wmsg()
Ejemplo n.º 2
0
    def showGeometry(self):

        if self.calcDone == True:
            """Visa geometri visualisering"""

            geometry = self.outputData.geometry

            self.geomFig = cfv.figure(self.geomFig)
            cfv.clf()
            cfv.drawGeometry(geometry, title="Geometry")
Ejemplo n.º 3
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(
        sqrt(pow(es[0], 2) - es[0] * es[1] + pow(es[1], 2) + 3 * es[2]))

    ## es: [sigx sigy tauxy]

# ---- Visualise results ----------------------------------------------------

cfu.info("Visualising...")

cfv.drawGeometry(g, drawPoints=False, labelCurves=True)

cfv.figure()
cfv.drawElementValues(vonMises,
                      coords,
                      edof,
                      dofsPerNode,
                      elType,
                      a,
                      doDrawMesh=True,
                      doDrawUndisplacedMesh=False,
                      title="Example 06 effective stress")

cfv.figure()
cfv.drawDisplacements(a,
                      coords,
Ejemplo n.º 4
0
# Degrees of freedom per node.

dofsPerNode= 1 

# Create mesh

coords, edof, dofs, bdofs, elementmarkers = cfm.createGmshMesh(geometry=g,
                                                               elType = elType,
                                                               elSizeFactor = 0.3,
                                                               dofsPerNode = dofsPerNode)

# ---- Visualise mesh -------------------------------------------------------

# Create two axes that are viewed from the same camera:

vv.figure()
a1 = vv.subplot(121)
a2 = vv.subplot(122)
cam = vv.cameras.ThreeDCamera()
a1.camera = a2.camera = cam

# Draw geometry and mesh

cfv.drawGeometry(g, axes=a1)
cfv.drawMesh(coords=coords, edof=edof, dofsPerNode=dofsPerNode, elType=elType, filled=False, axes=a2)

# Enter main loop

app = vv.use()
app.Create()
app.Run()
Ejemplo n.º 5
0
# ---- Solve problem --------------------------------------------------------

solver = cfslv.Plan2DSolver(mesh)

solver.addBC(rect.leftId, 0.0)
solver.addForceTotal(rect.topId, -10e5, dimension=2)

results = solver.execute()

# ---- Visualise results ----------------------------------------------------

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

cfv.figure()
cfv.drawGeometry(rect.geometry(), title="Geometry")

cfv.figure()
cfv.drawMesh(mesh.coords,
             mesh.edof,
             rect.dofsPerNode,
             rect.elementType,
             filled=True,
             title="Mesh")  #Draws the mesh.

cfv.figure()
cfv.drawDisplacements(results.a,
                      mesh.coords,
                      mesh.edof,
                      rect.dofsPerNode,
                      rect.elementType,
Ejemplo n.º 6
0
    # Determine element stresses and strains in the element.
    
    es, et = planqs(ex[i,:], ey[i,:], ep, D, ed[i,:]) 

    # Calc and append effective stress to list.    
    
    vonMises.append( math.sqrt( pow(es[0],2) - es[0]*es[1] + pow(es[1],2) + 3*es[2] ) ) 

    ## es: [sigx sigy tauxy]

# ---- Visualise results ----------------------------------------------------

print("Visualising...")

cfv.drawGeometry(g, drawPoints=False, labelCurves=True)

vv.figure()
cfv.drawElementValues(vonMises, coords, edof, dofsPerNode, elType, a, doDrawMesh=True, doDrawUndisplacedMesh=False, title="Example 06 effective stress")

vv.figure()
cfv.drawDisplacements(a, coords, edof, dofsPerNode, elType, doDrawUndisplacedMesh=True, title="Example 06")

# Make use of attribute 'nodesOnCurve' in GmshMesher to draw some arrows on 
# the right hand side of the mesh:

rightSideNodes = set()

# 4 and 5 are the IDs of the curves where we applied the forces.

for curveID in [4,5]: 
Ejemplo n.º 7
0
dofsPerNode = 1

# Create mesh

coords, edof, dofs, bdofs, elementmarkers = cfm.mesh(g, elType, 0.3,
                                                     dofsPerNode)

# ---- Visualise mesh -------------------------------------------------------

# Create two axes that are viewed from the same camera:

cfv.figure()
a1 = cfv.subplot(121)
a2 = cfv.subplot(122)
cam = cfv.camera3d()
a1.camera = a2.camera = cam

# Draw geometry and mesh

cfv.drawGeometry(g, axes=a1)
cfv.drawMesh(coords=coords,
             edof=edof,
             dofsPerNode=dofsPerNode,
             elType=elType,
             filled=False,
             axes=a2)

# Enter main loop

cfv.showAndWait()
Ejemplo n.º 8
0
 def drawGeometry(self):
     cfv.figure(self.fig1.nr)
     cfv.clf()
     cfv.drawGeometry(self.g)
Ejemplo n.º 9
0
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,
             title="Example 01")

# ----- Draw results

cfv.figure()
cfv.drawElementValues(vonMises,
Ejemplo n.º 10
0
# Degrees of freedom per node.

meshGen.dofsPerNode = 2
meshGen.elSizeFactor = 0.05

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

# ---- Visualise mesh -------------------------------------------------------

# Hold left mouse button to pan.
# Hold right mouse button to zoom.

# Draw the geometry.

cfv.drawGeometry(g, labelCurves=True)

# New figure window

cfv.figure()

# Draws the mesh.

cfv.drawMesh(coords=coords,
             edof=edof,
             dofsPerNode=meshGen.dofsPerNode,
             elType=meshGen.elType,
             filled=True,
             title="Example 02")

# Show grid
Ejemplo n.º 11
0
# Create mesh

coords, edof, dofs, bdofs, _ = cfm.mesh(g, elType, dofsPerNode)

# ---- Visualise mesh -------------------------------------------------------

# Hold Left Mouse button to rotate.
# Hold right mouse button to zoom.
# Hold SHIFT and left mouse button to pan.
# Hold SHIFT and right mouse button to change the field of view.
# Hold Ctrl and left mouse button to roll the camera.

# Draw geometry

cfv.drawGeometry(g, drawPoints=False)

# Draw mesh

cfv.figure()
cfv.drawMesh(coords=coords,
             edof=edof,
             dofsPerNode=dofsPerNode,
             elType=elType,
             filled=True)

# Add a text in world space

cfv.addText("This is a Text", pos=(1, 0.5, 0.5), angle=45)

# Add a label in the screen space
Ejemplo n.º 12
0
# ---- Compute element forces -----------------------------------------------

print("Computing element forces...")

ed = extractEldisp(edof, a)

for i in range(shape(ex)[0]):
    es, et, eci = flw2i8s(ex[i, :], ey[i, :], ep, Ddict[elementmarkers[i]], ed[i, :])

    # Do something with es, et, eci here.

# ---- Visualise results ----------------------------------------------------

print("Visualising...")

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

vv.figure()

# 8-node quads are drawn as simple quads.

cfv.drawMesh(coords, edof, dofsPerNode, elType, filled=False)

vv.figure()
cfv.drawNodalValues(a, coords, edof, dofsPerNode, elType, title="Example 7")
cfv.getColorbar().SetLabel("Temperature")
cfv.addText("The bend has high conductivity", (125, 125))
cfv.addText("This part has low conductivity", (160, -50))

# Enter main loop
Ejemplo n.º 13
0
    def show(self):
        # ------ Shows the geometry
        geometry = self.outputData.geometry
        a = self.outputData.a
        vonMises = self.outputData.stress
        coords = self.outputData.coords
        edof = self.outputData.edof
        dofsPerNode = self.outputData.mp[1]
        elType = self.outputData.mp[0]
        meshGen = self.outputData.meshGen
        stats = self.outputData.statistics
        fp = self.inputData.fp
        bp = self.inputData.bp
        w = stats[4][0]
        h = stats[4][1]
        units = self.inputData.units

        # Create the figure
        print("Visualizing...")
        cfv.close_all()
        if (self.geomFig):
            cfv.figure()
            cfv.drawGeometry(geometry,
                             title="Geometry",
                             drawPoints=False,
                             labelCurves=True)

        if (self.elValueFig):
            cfv.figure()
            cfv.drawElementValues(vonMises,
                                  coords,
                                  edof,
                                  dofsPerNode,
                                  elType,
                                  a,
                                  doDrawMesh=self.meshFig,
                                  doDrawUndisplacedMesh=False,
                                  title="Effective (Von Mises) Stress (Pa)")

            # ------ Add extra text
            node_x = [
                coords[int((edof[stats[0][0]][0] - 1) / 2), 0] +
                a[edof[stats[0][0]][0] - 1, 0], coords[int(
                    (edof[stats[0][0]][2] - 1) / 2), 0] +
                a[edof[stats[0][0]][2] - 1, 0], coords[int(
                    (edof[stats[0][0]][4] - 1) / 2), 0] +
                a[edof[stats[0][0]][4] - 1, 0]
            ]
            node_y = [
                coords[int((edof[stats[0][0]][0] - 1) / 2), 1] +
                a[edof[stats[0][0]][1] - 1, 0], coords[int(
                    (edof[stats[0][0]][2] - 1) / 2), 1] +
                a[edof[stats[0][0]][3] - 1, 0], coords[int(
                    (edof[stats[0][0]][4] - 1) / 2), 1] +
                a[edof[stats[0][0]][5] - 1, 0]
            ]
            node_centroid = [sum(node_x) / 3, sum(node_y) / 3]
            cfv.addText("Max Stress: {0:.2f} MPa".format(stats[0][1] / 1e6),
                        (stats[3][0] + 0.725 * w, stats[3][1] + 0.925 * h),
                        fontSize=15,
                        color='w')
            cfv.vv.plot([stats[3][0] + 0.715 * w, node_centroid[0]],
                        [stats[3][1] + 0.925 * h, node_centroid[1]],
                        lc='w')

        if (self.nodeValueFig):
            cfv.figure()
            cfv.drawDisplacements(a,
                                  coords,
                                  edof,
                                  dofsPerNode,
                                  elType,
                                  doDrawUndisplacedMesh=True,
                                  title="Displacements (m)")

            # Add markers
            symbols = {
                "rightarrow": "\u2192",
                "leftarrow": "\u2190",
                "uparrow": "\u2191",
                "downarrow": "\u2193",
                "nearrow": "\u2197",
                "nwarrow": "\u2196",
                "swarrow": "\u2199",
                "searrow": "\u2198",
                "fixed": "\u2215"
            }

            forceNodes = set()
            bcNodes = set()
            for j in range(len(fp[0])):
                for curveID in stats[2][fp[0][j]]:
                    forceNodes = forceNodes.union(
                        set(meshGen.nodesOnCurve[curveID]))
                for i in forceNodes:
                    x = coords[i,
                               0] + a[i * 2,
                                      0]  # Position of node with displacements
                    y = coords[i, 1] + a[i * 2 + 1, 0]
                    cfv.addText(symbols["rightarrow"], (x, y),
                                angle=fp[2][j],
                                fontSize=20,
                                color='g')
                for curveID in stats[2][bp[0][j]]:
                    bcNodes = bcNodes.union(set(meshGen.nodesOnCurve[curveID]))
                for i in bcNodes:
                    x = coords[i,
                               0] + a[i * 2,
                                      0]  # Position of node with displacements
                    y = coords[i, 1] + a[i * 2 + 1, 0]
                    cfv.addText(symbols["fixed"], (x, y),
                                fontSize=15,
                                color='r')

            # --- Add additional text
            cfv.addText("Forces Applied: {0:6.2f} kN/m".format(
                self.inputData.fp[1][0] * U2SI[units][1] / 1e3),
                        (stats[3][0] + 0.725 * w, stats[3][1] + 0.925 * h),
                        fontSize=15,
                        color='g')
            cfv.addText("Boundary Condition: {0:6.2f}m displacement".format(
                self.inputData.bp[1][0] * U2SI[units][0]),
                        (stats[3][0] + 0.625 * w, stats[3][1] + 0.95 * h),
                        fontSize=15,
                        color='r')
            node_x = coords[int((edof[stats[1][0][0]][stats[1][0][1]] - 1) / 2), 0] +\
                     + a[edof[stats[1][0][0]][stats[1][0][1]] - 1, 0]
            node_y = coords[int((edof[stats[1][0][0]][stats[1][0][1]] - 1) / 2), 1] +\
                     + a[edof[stats[1][0][0]][stats[1][0][1]+1] - 1, 0]
            cfv.addText("Max Displacement: {0:6.2f} mm".format(stats[1][1] *
                                                               1e3),
                        (stats[3][0] + 0.725 * w, stats[3][1] + 0.9 * h),
                        fontSize=15,
                        color='w')
            cfv.vv.plot([stats[3][0] + 0.715 * w, node_x],
                        [stats[3][1] + 0.9 * h, node_y],
                        lc='w')
Ejemplo n.º 14
0
 def drawGeometry(self, figGeometry):
     """Draw geometry in provided figure"""
     cfv.figure(figGeometry.nr) 
     cfv.clf()
     cfv.drawGeometry(self.rect.geometry(), title="Geometry")
Ejemplo n.º 15
0
# Degrees of freedom per node.

dofsPerNode = 2 

coords, edof, dofs, bdofs, elementmarkers = cfm.createGmshMesh(g, elType = elType,
                                                             elSizeFactor = 0.05,
                                                             dofsPerNode = dofsPerNode)

# ---- Visualise mesh -------------------------------------------------------

# Hold left mouse button to pan.
# Hold right mouse button to zoom.

# Draw the geometry.

cfv.drawGeometry(g, labelCurves=True)

# New figure window

vv.figure() 

cfv.drawMesh(coords=coords, edof=edof, dofsPerNode=dofsPerNode, elType=elType, filled=True, title="Example 02") #Draws the mesh.

# Show grid

vv.gca().axis.showGrid = True 

# Enter main loop

app = vv.use()
app.Create()
Ejemplo n.º 16
0
bc, bcVal = cfu.applybc(bdofs, bc, bcVal, 90, 10.0)

# solving equation
a, r = cfc.solveq(K, f, bc, bcVal)
ed = cfc.extractEldisp(edof, a)

maxFlow = []  # empty list to store flow

# calculating element force
for i in range(edof.shape[0]):
    es, et, eci = cfc.flw2i4s(ex[i, :], ey[i, :], ep, D, ed[i, :])
    maxFlow.append(np.sqrt(pow(es[0, 0], 2) + pow(es[0, 1], 2)))

# visualization
cfv.figure()
cfv.drawGeometry(g, title='Geometry')
cfv.showAndWait()

cfv.figure()
cfv.drawElementValues(maxFlow,
                      coords,
                      edof,
                      dofsPerNode,
                      elType,
                      None,
                      title='Max flows')

cfv.colorBar().SetLabel("Flow")
cfv.showAndWait()

cfv.figure()
Ejemplo n.º 17
0
#  (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
#  marker of a given element (index).

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

# ---- Visualise mesh -------------------------------------------------------

# Hold left mouse button to pan.
# Hold right mouse button to zoom.

# Draw the geometry. Note that surfaces and volumes are not drawn at all by 
# this function.

cfv.drawGeometry(g)

# New figure window

vv.figure() 

cfv.drawMesh(coords=coords, edof=edof, dofsPerNode=dofsPerNode, elType=elType, filled=True, title="Example 01") #Draws the mesh.

cfv.addText("This is a Text", pos=(1, -0.3), angle=45)  #Adds a text in world space

ourLabel = cfv.addLabel("This is a Label", pos=(100,200), angle=-45) #Adds a label in the screen space
ourLabel.text = "Label, changed." #We can change the attributes of labels and texts, such as color, text, and position.
ourLabel.textColor = 'r'  #Make it red. (1,0,0) would also have worked.
ourLabel.position = (20,30)

# Enter main loop:
Ejemplo n.º 18
0
print("Computing element forces...")

ed = cfc.extractEldisp(edof, a)

for i in range(np.shape(ex)[0]):
    es, et, eci = cfc.flw2i8s(
        ex[i, :], ey[i, :], ep, Ddict[elementmarkers[i]], ed[i, :])

    # Do something with es, et, eci here.

# ---- Visualise results ----------------------------------------------------

print("Visualising...")

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

cfv.figure()

# 8-node quads are drawn as simple quads.

cfv.drawMesh(coords, edof, dofs_per_node, el_type, filled=False)

cfv.figure()
cfv.draw_nodal_values(a, coords, edof, dofs_per_node,
                      el_type, title="Example 7")
cfv.get_color_bar().SetLabel("Temperature")
cfv.add_text("The bend has high conductivity", (125, 125))
cfv.add_text("This part has low conductivity", (160, -50))

# Enter main loop
Ejemplo n.º 19
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( sqrt( pow(es[0],2) - es[0]*es[1] + pow(es[1],2) + 3*es[2] ) ) 

    ## es: [sigx sigy tauxy]

# ---- Visualise results ----------------------------------------------------

cfu.info("Visualising...")

cfv.drawGeometry(g, draw_points=False, label_curves=True)

cfv.figure()
cfv.draw_element_values(vonMises, coords, edof, mesh.dofs_per_node, mesh.el_type, a, draw_elements=True, draw_undisplaced_mesh=False, title="Example 06 effective stress")

cfv.figure()
cfv.draw_displacements(a, coords, edof, mesh.dofs_per_node, mesh.el_type, draw_undisplaced_mesh=True, title="Example 06")

# Make use of attribute 'nodesOnCurve' in GmshMesher to draw some arrows on 
# the right hand side of the mesh:

rightSideNodes = set()

# 4 and 5 are the IDs of the curves where we applied the forces.

for curveID in [4,5]: 
Ejemplo n.º 20
0
 def drawGeometry(self, figGeometry):
     """Draws geometry in specified figure"""
     cfv.figure(figGeometry.nr)
     cfv.clf()
     cfv.drawGeometry(self.g, drawPoints=False, labelCurves=True)
Ejemplo n.º 21
0
# Create mesh

coords, edof, dofs, bdofs, _ = cfm.createGmshMesh(geometry = g, elType = elType,
                                              dofsPerNode = dofsPerNode)

# ---- Visualise mesh -------------------------------------------------------

# Hold Left Mouse button to rotate.
# Hold right mouse button to zoom.
# Hold SHIFT and left mouse button to pan.
# Hold SHIFT and right mouse button to change the field of view.
# Hold Ctrl and left mouse button to roll the camera. 

# Draw geometry

cfv.drawGeometry(g, drawPoints=False)

# Draw mesh

vv.figure()
cfv.drawMesh(coords=coords, edof=edof, dofsPerNode=dofsPerNode, elType=elType, filled=True)

# Add a text in world space

cfv.addText("This is a Text", pos=(1, 0.5, 0.5), angle=45)  

# Add a label in the screen space

ourLabel = cfv.addLabel("This is a Label", pos=(20,30), angle=-45) 

# We can change the attributes of labels and texts, such as color and position.