def updateGeometry(self): """Update geometry from set parameters""" rect = cfs.Rectangle(self.w, self.h, elementType=3, dofsPerNode=2, maxArea=self.maxArea) rect.t = self.t rect.v = self.v rect.E = self.E rect.ptype = 1 rect.ep = [rect.ptype, rect.t] rect.D = cfc.hooke(rect.ptype, rect.E, rect.v) self.rect = rect
def solve(self): """Solve problem""" self.updateGeometry() self.updateMesh() self.ep = [self.ptype, self.t] self.D = cfc.hooke(self.ptype, self.E, self.v) cfu.info("Assembling system matrix...") nDofs = np.size(self.dofs) ex, ey = cfc.coordxtr(self.edof, self.coords, self.dofs) K = np.zeros([nDofs, nDofs]) for eltopo, elx, ely in zip(self.edof, ex, ey): Ke = cfc.planqe(elx, ely, self.ep, self.D) cfc.assem(eltopo, K, Ke) cfu.info("Solving equation system...") f = np.zeros([nDofs, 1]) bc = np.array([], 'i') bcVal = np.array([], 'i') bc, bcVal = cfu.applybc(self.bdofs, bc, bcVal, 5, 0.0, 0) cfu.applyforce(self.bdofs, f, 7, 10e5, 1) self.a, self.r = cfc.solveq(K, f, bc, bcVal) cfu.info("Computing element forces...") ed = cfc.extractEldisp(self.edof, self.a) self.vonMises = [] # For each element: for i in range(self.edof.shape[0]): # Determine element stresses and strains in the element. es, et = cfc.planqs(ex[i, :], ey[i, :], self.ep, self.D, ed[i, :]) # Calc and append effective stress to list. self.vonMises.append( sqrt( pow(es[0], 2) - es[0] * es[1] + pow(es[1], 2) + 3 * es[2]))
import calfem.utils as cfu import numpy as np from math import * # ----- Problem parameters l = 5.0 h = 1.0 t = 0.2 v = 0.35 E = 2.1e9 ptype = 1 ep = [ptype, t] D = cfc.hooke(ptype, E, v) left_support = 10 right_support = 20 top_line = 30 # ----- Define geometry g = cfg.Geometry() g.point([0.0, 0.0], marker=left_support) # point 0 g.point([l, 0.0], marker=right_support) # point 1 g.point([l, h]) # point 2 g.point([0.0, h]) # point 2 g.spline([0, 1]) # line 0
cfu.enableLogging() # ---- General parameters --------------------------------------------------- # Define marker constants instead of using numbers in the code cfu.info("Creating rectangle") rect = cfs.Rectangle(5.0, 1.0, elementType=3, dofsPerNode=2, maxArea=0.08) rect.t = 0.2 rect.v = 0.35 rect.E = 2e9 rect.ptype = 1 rect.ep = [rect.ptype, rect.t] rect.D = cfc.hooke(rect.ptype, rect.E, rect.v) cfu.info("Creating mesh...") mesh = cfs.ShapeMesh(rect) # ---- Solve problem -------------------------------------------------------- solver = cfslv.Plan2DSolver(mesh) solver.addBC(rect.leftId, 0.0) solver.addForceTotal(rect.topId, -10e5, dimension=2) results = solver.execute() # ---- Visualise results ----------------------------------------------------
import numpy as np from scipy.sparse import lil_matrix # ---- General parameters --------------------------------------------------- cfu.enableLogging() t = 0.2 v = 0.35 E1 = 2e9 E2 = 0.2e9 ptype = 1 ep = [ptype,t] D1 = cfc.hooke(ptype, E1, v) D2 = cfc.hooke(ptype, E2, v) # Define marker constants instead of using numbers in the code markE1 = 55 markE2 = 66 markFixed = 70 markLoad = 90 # Create dictionary for the different element properties elprop = {} elprop[markE1] = [ep, D1] elprop[markE2] = [ep, D2]
import calfem.utils as cfu import numpy as np from scipy.sparse import lil_matrix cfu.enableLogging() # ---- General parameters --------------------------------------------------- t = 0.2 v = 0.35 E1 = 2e9 E2 = 0.2e9 ptype = 1 ep = [ptype,t] D1 = cfc.hooke(ptype, E1, v) D2 = cfc.hooke(ptype, E2, v) # Define marker constants instead of using numbers in the code mark_E1 = 55 mark_E2 = 66 mark_fixed = 70 mark_load = 90 # Create dictionary for the different element properties elprop = {} elprop[mark_E1] = [ep, D1] elprop[mark_E2] = [ep, D2]
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