Beispiel #1
0
    def drawMesh(self):
        cfv.figure(self.fig2.nr)
        cfv.clf()
        cfv.drawMesh(coords=self.coords,
                     edof=self.edof,
                     dofsPerNode=self.meshGen.dofsPerNode,
                     elType=self.meshGen.elType,
                     filled=True,
                     title="Example 01")

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

        ourLabel = cfv.label("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)
Beispiel #2
0
    def drawDisplacements(self, figDisplacements):
        """Draws displacements in specified figure"""
        cfv.figure(figDisplacements.nr)
        cfv.clf()
        cfv.drawDisplacements(self.a,
                              self.coords,
                              self.edof,
                              self.mesh.dofsPerNode,
                              self.mesh.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]:

            # Get the nodes, without duplicates.

            rightSideNodes = rightSideNodes.union(
                set(self.mesh.nodesOnCurve[curveID]))

        for i in rightSideNodes:

            # Position of the node with displacements.

            x = self.coords[i, 0] + self.a[i * 2, 0]
            y = self.coords[i, 1] + self.a[i * 2 + 1, 0]

            # A poor man's force indicator. Could also use vv.plot()

            cfv.addText("\rightarrow", (x, y), fontSize=20, color='g')
Beispiel #3
0
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

app = vv.use()
app.Create()
app.Run()

print("Done.")
Beispiel #4
0
# Draw the geometry. Note that surfaces and volumes are not drawn at all by 
# this function.

cfv.drawGeometry(g)

# New figure window

cfv.figure() 

# Draw the mesh.

cfv.drawMesh(
    coords=coords, 
    edof=edof, 
    dofsPerNode=mesh.dofs_per_node, 
    elType=mesh.el_type, 
    filled=True, 
    title="Example 01"
    ) 

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

ourLabel = cfv.label("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:

cfv.showAndWait()
Beispiel #5
0
# 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]:

    # Get the nodes, without duplicates.

    rightSideNodes = rightSideNodes.union(set(meshGen.nodesOnCurve[curveID]))

for i in rightSideNodes:

    # Position of the node with displacements.

    x = coords[i, 0] + a[i * 2, 0]
    y = coords[i, 1] + a[i * 2 + 1, 0]

    # A poor man's force indicator. Could also use vv.plot()

    cfv.addText("\rightarrow", (x, y), fontSize=20, color='g')

# Enter main loop

cfv.showAndWait()

print("Done.")
Beispiel #6
0
# 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]: 

    # Get the nodes, without duplicates.

    rightSideNodes = rightSideNodes.union(set(meshGen.nodesOnCurve[curveID])) 
    
for i in rightSideNodes:

    # Position of the node with displacements.

    x = coords[i,0] + a[i*2, 0]     
    y = coords[i,1] + a[i*2+1, 0]
    
    # A poor man's force indicator. Could also use vv.plot()    
    
    cfv.addText("\rightarrow", (x, y), fontSize=20, color='g') 

# Enter main loop

app = vv.use()
app.Create()
app.Run()

print("Done.")
Beispiel #7
0
# 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.

ourLabel.text = "Label, changed." 

# Make it red. (1,0,0) would also have worked.

ourLabel.textColor = 'r'  

# Matlab style axes (three axes in the background instead of a cube)
Beispiel #8
0
# 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

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.

ourLabel.text = "Label, changed."

# Make it red. (1,0,0) would also have worked.

ourLabel.textColor = 'r'

# Matlab style axes (three axes in the background instead of a cube)
Beispiel #9
0
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, dofsPerNode, elType, filled=False)

cfv.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

cfv.showAndWait()

print("Done.")
Beispiel #10
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')
Beispiel #11
0
#  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:
app = vv.use()
app.Create()
app.Run()