def showMesh(self): if self.calcDone == True: self.meshFig = cfv.figure(self.meshFig) cfv.drawMesh(self.outputData.coords, self.outputData.edof, self.outputData.dofsPerNode, self.outputData.elType, filled=True, title="Mesh") #Draws the mesh.
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()
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)
# 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()
idof2 = i2 * 2 + 1 idof3 = i3 * 2 + 1 idof4 = i4 * 2 + 1 elnods[iel, :] = [i1, i2, i3, i4] eldofs[iel, :] = [ idof1, idof1 + 1, idof2, idof2 + 1, idof3, idof3 + 1, idof4, idof4 + 1 ] iel += 1 # Draw the mesh. if bDrawMesh: cfv.drawMesh(coords=coords, edof=eldofs, dofsPerNode=2, elType=3, filled=True, title="4 node quad elements") cfv.showAndWait() # Set fixed boundary condition on left side, i.e. nodes 0-nNody bc = np.array(np.zeros(nNody * 2), 'i') idof = 1 for i in range(nNody): idx = i * 2 bc[idx] = idof bc[idx + 1] = idof + 1 idof += 2 # Assemble stiffness matrix
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, doDrawUndisplacedMesh=False, title="Displacements", magnfac=1) cfv.figure() cfv.drawElementValues(results.elForces,
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()
rect.D = np.diag([1.7, 1.7]) cfu.info("Creating mesh...") mesh = cfs.ShapeMesh(rect) # ---- Solve problem -------------------------------------------------------- solver = cfslv.Flow2DSolver(mesh) solver.addBC(rect.left_id, 0.0) solver.addBC(rect.right_id, 120.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.dofs_per_node, rect.element_type, filled=True, title="Mesh") #Draws the mesh. cfv.figure() cfv.drawNodalValues(results.a, mesh.coords, mesh.edof, rect.dofs_per_node, rect.element_type) cfv.showAndWait()
nod9[1], nod9[5], nod9[7], nod9[3], nod9[4]] iel += 1 for iel in range(elnods.shape[0]): eldofs[iel, ::2] = elnods[iel, :] * 2 + 1 # The x dofs eldofs[iel, 1::2] = elnods[iel, :] * 2 + 2 # The y dofs # Draw the mesh. if bDrawMesh: cfv.drawMesh( coords=coords, edof=eldofs, dofsPerNode=2, elType=elTypeInfo[0], filled=True, title=elTypeInfo[1]) cfv.showAndWait() # Extract element coordinates ex, ey = cfc.coordxtr(eldofs, coords, dofs) # Set fixed boundary condition on left side, i.e. nodes 0-nNody bc = np.array(np.zeros(numNodesY*2), 'i') idof = 1 for i in range(numNodesY): idx = i*2 bc[idx] = idof bc[idx+1] = idof+1
ed = cfc.extractEldisp(edof,a) maxFlow = [] for i in range(edof.shape[0]): es, et, eci = cfc.flw2i4s(ex[i,:], ey[i,:], ep, D, ed[i,:]) maxFlow.append( math.sqrt( math.pow(es[0,0],2) + math.pow(es[0,1],2)) ) # ------ Draw results ------------ cfv.figure() cfv.drawGeometry(g, title="Geometry") cfv.figure() cfv.drawElementValues(maxFlow, coords, edof, dofsPerNode, elType, None, doDrawMesh=False, title="Max flows") cfv.figure() cfv.drawMesh(coords, edof, dofsPerNode, elType, filled=True, title="Mesh") cfv.figure() cfv.drawNodalValues(a, coords, edof, dofsPerNode, elType, doDrawMesh=False, title="Nodal values") cfv.colorBar().SetLabel("Flow") print("Done drawing...") cfv.showAndWait()
meshGen = cfm.GmshMeshGenerator(g) # Element type 3 is quad. (2 is triangle. See user manual for more element types) meshGen.elType = 3 # Degrees of freedom per node. meshGen.dofsPerNode = 1 coords, edof, dofs, bdofs, elementmarkers = meshGen.create() # ---- Visualise mesh ------------------------------------------------------- # Draw geometry cfv.drawGeometry(g) # Draw mesh cfv.figure() cfv.drawMesh(coords=coords, edof=edof, dofsPerNode=meshGen.dofsPerNode, elType=meshGen.elType, filled=True) # Enter main loop cfv.showAndWait()
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.")
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. cfv.figure() cfv.drawDisplacements(a, coords, edof, dofsPerNode, elType, doDrawUndisplacedMesh=False, title="Displacements", magnfac=25.0) cfv.figure() cfv.drawElementValues(vonMises, coords, edof, dofsPerNode, elType, a, doDrawMesh=True, doDrawUndisplacedMesh=False, title="Effective Stress", magnfac=25.0) cfv.colorBar().SetLabel("Effective stress") print("Done drawing...")
def drawMesh(self, figMesh): """Draw mesh in provided figure""" cfv.figure(figMesh.nr) cfv.clf() cfv.drawMesh(self.mesh.coords, self.mesh.edof, self.rect.dofsPerNode, self.rect.elementType, filled=True, title="Mesh") #Draws the mesh.
vonMises.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.drawGeometry(g, title="Geometry") cfv.figure() cfv.drawMesh(coords=coords, edof=edof, dofsPerNode=dofsPerNode, elType=elType, filled=True, title="Mesh") #Draws the mesh. cfv.figure() cfv.drawDisplacements(a, coords, edof, dofsPerNode, elType, doDrawUndisplacedMesh=False, title="Displacements", magnfac=25.0) cfv.figure() cfv.drawElementValues(vonMises,
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.")
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 cfv.show_and_wait() print("Done.")
# ---- 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. ourLabel.text = "Label, changed." # Make it red. (1,0,0) would also have worked.
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, coords, edof, mesh.dofsPerNode, mesh.elType, a, doDrawMesh=True, doDrawUndisplacedMesh=False, title="Example 06 effective stress")
idof3 = i3*2 +1 idof4 = i4*2 +1 elnods[iel,:] = [i1, i2, i3] eldofs[iel,:] = [idof1,idof1+1, idof2,idof2+1, idof3,idof3+1] iel += 1 elnods[iel,:] = [i3,i4,i1] eldofs[iel,:] = [idof3,idof3+1, idof4,idof4+1, idof1,idof1+1] iel += 1 # Draw the mesh. if bDrawMesh: cfv.drawMesh( coords=coords, edof=eldofs, dofsPerNode=2, elType=2, filled=True, title="6 node triangle elements") cfv.showAndWait() # Set fixed boundary condition on left side, i.e. nodes 0-nNody bc = np.array(np.zeros(nNody*2),'i') idof = 1 for i in range(nNody): idx = i*2 bc[idx] = idof bc[idx+1] = idof+1 idof += 2 # Assemble stiffness matrix