def on_create_Ke(self, elx, ely, element_type): Ke = None if self.mesh.shape.element_type == 2: Ke = cfc.plante(elx, ely, self.mesh.shape.ep, self.mesh.shape.D) else: Ke = cfc.planqe(elx, ely, self.mesh.shape.ep, self.mesh.shape.D) return Ke
if numElementNodes == 3: K_el, f_el = tri.tri3e(ex[iel], ey[iel], Dmat, thickness, eq) # K_el_s, f_el_s = cfc.plante(ex[iel], ey[iel], ep, Dmat, eq) # f_el_s = f_el_s.T # f_error = np.max(np.abs(f_el - f_el_s)) # K_error = np.max(np.abs(K_el - K_el_s)) elif numElementNodes == 6: K_el, f_el = tri.tri6e(ex[iel], ey[iel], Dmat, thickness, eq) elif numElementNodes == 4: K_el, f_el = quad.quad4e(ex[iel], ey[iel], Dmat, thickness, eq) elif numElementNodes == 9: K_el, f_el = quad.quad9e(ex[iel], ey[iel], Dmat, thickness, eq) else: if numElementNodes == 3: # core version of plante /tri3el K_el, f_el = cfc.plante(ex[iel], ey[iel], ep, Dmat, eq) # Transpose so correct dim for assem f_el = f_el.T elif numElementNodes == 4: # Number of intergration points. 1, 2 or 3 n = 2 ep = np.array([ep[0], ep[1], n]) K_el, f_el = cfc.plani4e(ex[iel], ey[iel], ep, Dmat, eq) f_el = f_el.T cfc.assem(eldofs[iel], K, K_el, R, f_el) r, R0 = cfc.solveq(K, R, bc) nodMiddle = numNodesY//2 + 1 # Mid nod on right edge xC = r[-(nodMiddle*2), 0] # 2 dofs per node, so this is the middle dof on end
# marker of a given element (index). coords, edof, dofs, bdofs, elementmarkers = meshGen.create() # ---- Solve problem -------------------------------------------------------- nDofs = np.size(dofs) K = lil_matrix((nDofs,nDofs)) ex, ey = cfc.coordxtr(edof, coords, dofs) print("Assembling K... ("+str(nDofs)+")") for eltopo, elx, ely, elMarker in zip(edof, ex, ey, elementmarkers): if elType == 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) print("Applying bc and loads...") bc = np.array([],'i') bcVal = np.array([],'i') bc, bcVal = cfu.applybc(bdofs, bc, bcVal, markFixed, 0.0) f = np.zeros([nDofs,1]) cfu.applyforcetotal(bdofs, f, markLoad, value = -10e5, dimension=2)
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.")
# 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') bc, bcVal = cfu.applybc(bdofs, bc, bcVal, mark_fixed, 0.0) f = np.zeros([nDofs,1]) cfu.applyforcetotal(bdofs, f, mark_load, value = -10e5, dimension=2)