def ComputeMass(self, node, element, dofMap=None): etype = None mtype = None if (dofMap == None): dofMap = dmap.FixedDofMap(self.dpn) #mespace = len(element)*(element[0].NumNodes()*self.dpn)**2 mdata = basic.DelayedAssm(element, self.dpn) for e in element: ecoord = node[e.Connectivity(), :] if (not etype == e.Type()): etype = e.Type() qr = e.QuadratureRule(2 * (e.Order())) nne = e.NumNodes() if (not e.Material() == mtype): mtype = e.prop.material rho = mtype.matprop['rho'] me = np.zeros((nne, nne)) for q in xrange(qr[1].size): qpt = qr[0][q] qwt = qr[1][q] jac = e.Jacobian(ecoord, qpt) N = e.N(qpt) me = me + rho * np.outer(N, N) * jac * qwt # scatter me into M for s in self.SpacialDim(): sctr = dofMap.Sctr(e.Connectivity(), s) mdata.AddLocalMatrix(me, sctr) return mdata.GetCsrMatrix()
def ComputeStress(self, node, element, disp, dofMap=None): if (dofMap == None): dofMap = dmap.FixedDofMap(self.dpn) ne = len(element) strain = np.zeros((ne, self.vdim), dtype=basic.FLOAT_TYPE) stress = np.zeros((ne, self.vdim), dtype=basic.FLOAT_TYPE) svm = np.zeros(ne, dtype=basic.FLOAT_TYPE) mtype = None ei = 0 for e in element: ecoord = node[e.Connectivity(), :] #sctr = elem.sctr_array( e.Connectivity(), self.dpn ) sctr = dofMap.Sctr(e.Connectivity(), range(self.dpn)) if (not e.Material() == mtype): mtype = e.prop.material C = self.GetMaterialStiffness(e) B, jac = e.BMat(ecoord) strain[ei, :] = np.dot(B, disp[sctr]) stress[ei, :] = np.dot(C, strain[ei]) svm[ei] = self.ComputeMisesStress(stress[ei]) ei = ei + 1 return [stress, svm, strain]
def ComputeStiffness(self, node, element, dofMap=None): etype = None mtype = None if (dofMap == None): dofMap = dmap.FixedDofMap(self.dpn) #kespace = len(element)*(element[0].NumNodes()*self.dpn)**2 kdata = basic.DelayedAssm(element, self.dpn) for e in element: ecoord = node[e.Connectivity(), :] #pdb.set_trace() sctr = dofMap.Sctr(e.Connectivity(), dofMap.LDOFs()) if (not etype == e.Type()): etype = e.Type() qr = e.QuadratureRule(2 * (e.Order())) kdim = e.NumNodes() * self.dpn if (not e.Material() == mtype): mtype = e.prop.material C = self.GetMaterialStiffness(e) ke = np.zeros((kdim, kdim)) for q in xrange(qr[1].size): qpt = qr[0][q] qwt = qr[1][q] ipm = e.BMat(ecoord, qpt) jac = ipm[1] B = ipm[0] ke = ke + np.dot(np.dot(B.T, C), B) * jac * qwt # scatter ke into K kdata.AddLocalMatrix(ke, sctr) return kdata.GetCsrMatrix()
print '********************* 3D FINITE ELEMENT PROGRAM *********************' print 'Initializing grid' # define the finite element mesh pwidth = 20 plength = 20 pheight = 5 mat0 = matl.LinearElasticMat(10e6, .33, 2.45e-4) # linear elastic isotropic material prop0 = prop.Solid3D(mat0) # 3D solid property fegrid = mesh.MeshHexa8( np.array([ [0,0,0], [plength,0,0], [plength,pwidth,0], [0,pwidth,0], \ [0,0,pheight], [plength,0,pheight], [plength,pwidth,pheight], [0,pwidth,pheight] ]),\ 21, 21, 6, prop0 ) # setup a simple dofmap with 3 dof per node dofMap = dmap.FixedDofMap(3) formulation = prob.Problem3D() print 'Computing stiffness matrix' # compute the stiffness matrix Kmat = formulation.ComputeStiffness(fegrid.node, fegrid.element, dofMap) # define symmetry boundary conditions spcs = bcs.EssentialBCs() spcs.AddSpcs(fegrid.FaceNIDs(1), [0], dofmap=dofMap) # fix -x face in x spcs.AddSpcs(fegrid.FaceNIDs(3), [1], dofmap=dofMap) # fix -y face in y spcs.AddSpcs(fegrid.FaceNIDs(5), [2], dofmap=dofMap) # fix -z face in z # define rhs load loads = bcs.NaturalBCs() loads.AddTraction(fegrid.FaceElem(0), [100.0, 0.0, 0.0]) # load on the +x face
fext[sctr] = fext[sctr] + fe return fext #--------------------------------------------- import prop import meshing as mesh # define the finite element mesh pwidth=20 pheight=5 mat0 = NewtonianFluid( ) prop0 = prop.PlaneStress( mat0, 1.0 ) fegrid = mesh.MeshQuad4( np.array([[0,0],[pwidth,0],[pwidth,pheight],[0,pheight]]), 5, 2, prop0 ) dofmap = dmap.FixedDofMap(2) # define the velocity boundary conditions inflow = bcs.NaturalBCs() inflow.AddTraction( fegrid.EdgeElem(3), [10.0, 0.0] ) inflowspcs = bcs.EssentialBCs() inflowspcs.AddSpcs( fegrid.EdgeNIDs(3), [0], [10.0], dofmap=dofmap ) # fix left edge in x loads = bcs.NaturalBCs() # if there are external wall tractions on the flow loads.AddTraction( fegrid.EdgeElem(0), [10.0, 0.0] ) # set the initial conditions formulation = CBSMethod(sdim=2) dt=.1 U=np.zeros(20,float) U[::2]=fegrid.node[:,0]