NEUMANN_BOUNDARY = 1 DIRICHLET_BOUNDARY = 2 m.set_region(NEUMANN_BOUNDARY, ftop) m.set_region(DIRICHLET_BOUNDARY, fbot) # assembly nbd = mfd.nbdof() print "nbd: ", nbd F = gf.asm_boundary_source(NEUMANN_BOUNDARY, mim, mfu, mfd, np.repeat([[0], [-100], [0]], nbd, 1)) print "F.shape: ", F.shape print "mfu.nbdof(): ", mfu.nbdof() print "np.repeat([[0],[-100],[0]],nbd,1).shape:", np.repeat([[0], [-100], [0]], nbd, 1).shape K = gf.asm_linear_elasticity(mim, mfu, mfd, np.repeat([Lambda], nbd), np.repeat([Mu], nbd)) print "K.info: ", K.info # Spmat instance print "np.repeat([Lambda], nbd).shape:", np.repeat([Lambda], nbd).shape print "np.repeat([Mu], nbd).shape:", np.repeat([Mu], nbd).shape # handle Dirichlet condition (H, R) = gf.asm_dirichlet(DIRICHLET_BOUNDARY, mim, mfu, mfd, mfd.eval('numpy.identity(3)'), mfd.eval('[0,0,0]')) print "H.info: ", H.info # Spmat instance print "R.shape: ", R.shape print "mfd.eval('numpy.identity(3)').shape: ", mfd.eval( 'numpy.identity(3)').shape print "mfd.eval('[0,0,0]').shape: ", mfd.eval('[0,0,0]').shape (N, U0) = H.dirichlet_nullspace(R) print "N.info: ", N.info # Spmat instance
ftop = m.faces_from_pid(pidtop) fbot = m.faces_from_pid(pidbot) print "create boundary region" NEUMANN_BOUNDARY = 1 DIRICHLET_BOUNDARY = 2 m.set_region(NEUMANN_BOUNDARY,ftop) m.set_region(DIRICHLET_BOUNDARY,fbot) print "create a MeshFem object" mfd = gf.MeshFem(m, 1) # data print "assign the FEM" mfd.set_fem(gf.Fem('FEM_QK(3,3)')) print "assembly" nbd = mfd.nbdof() K = gf.asm_linear_elasticity(mim, mfu, mfd, np.repeat([Lambda], nbd), np.repeat([Mu], nbd)) M = gf.asm_mass_matrix(mim, mfu)*rho K.save('hb', 'K.hb') M.save('hb', 'M.hb') print "solve" A = io.hb_read('M.hb') B = io.hb_read('K.hb') K = B.todense() np.savetxt("K.txt", K, fmt=' (%+.18e) ')
############################################################################### # We get the mass and stiffness matrices using asm function. # mass_matrixs = [] linear_elasticitys = [] for i, (mfu, mfd, mim) in enumerate(zip(mfus, mfds, mims)): mass_matrix = gf.asm_mass_matrix(mim, mfu, mfu) mass_matrix.scale(rho) mass_matrixs.append(mass_matrix) lambda_d = np.repeat(clambda, mfd.nbdof()) mu_d = np.repeat(cmu, mfd.nbdof()) linear_elasticity = gf.asm_linear_elasticity(mim, mfu, mfd, lambda_d, mu_d) linear_elasticitys.append(linear_elasticity) mass_matrix.save("hb", "M" + "{:02}".format(i) + ".hb") linear_elasticity.save("hb", "K" + "{:02}".format(i) + ".hb") print("Time for assemble matrix", time.process_time() - t) t = time.process_time() ############################################################################### # Solve the eigenproblem. # # Compute the residual error for SciPy. # # :math:`Err=\frac{||(K-\lambda.M).\phi||_2}{||K.\phi||_2}` #
def import_fem2(sico): """ Build a mesh object using getfem. We use getfem++ to build the finite element model and to fill in the operators required by siconos: - the mass matrix (Mass) - the stiffness matrix (Stiff) - the matrix that links global coordinates and local coord. at contact points (H) """ ############################ # The geometry and the mesh ############################ dimX = 10.01 ; dimY = 10.01 ; dimZ = 10.01 stepX = 1.0 ; stepY = 1.0 ; stepZ = 1.0 x=np.arange(0,dimX,stepX) y=np.arange(0,dimY,stepY) z=np.arange(0,dimZ,stepZ) m = gf.Mesh('regular simplices', x,y,z) m.set('optimize_structure') # Export the mesh to vtk m.export_to_vtk("BlockMesh.vtk") # Create MeshFem objects # (i.e. assign elements onto the mesh for each variable) mfu = gf.MeshFem(m,3) # displacement mfd = gf.MeshFem(m,1) # data mff = gf.MeshFem(m,1) # for plot von-mises # assign the FEM mfu.set_fem(gf.Fem('FEM_PK(3,1)')) mfd.set_fem(gf.Fem('FEM_PK(3,0)')) mff.set_fem(gf.Fem('FEM_PK_DISCONTINUOUS(3,1,0.01)')) # mfu.export_to_vtk("BlockMeshDispl.vtk") # Set the integration method mim = gf.MeshIm(m,gf.Integ('IM_TETRAHEDRON(5)')) # Summary print(' ==================================== \n Mesh details: ') print(' Problem dimension:', mfu.qdim(), '\n Number of elements: ', m.nbcvs(), '\n Number of nodes: ', m.nbpts()) print(' Number of dof: ', mfu.nbdof(), '\n Element type: ', mfu.fem()[0].char()) print(' ====================================') ########################### # Set the parameters # for the constitutive law ########################### E = 1e3 # Young modulus Nu = 0.3 # Poisson coef. # Lame coeff. Lambda = E*Nu/((1+Nu)*(1-2*Nu)) Mu = E/(2*(1+Nu)) # Density Rho=7800 ############################ # Boundaries detection ############################ allPoints = m.pts() # Bottom points and faces cbot = (abs(allPoints[2,:]) < 1e-6) pidbot = np.compress(cbot,list(range(0,m.nbpts()))) fbot = m.faces_from_pid(pidbot) BOTTOM = 1 m.set_region(BOTTOM,fbot) # Top points and faces ctop = (abs(allPoints[2,:]) > dimZ-stepZ) pidtop = np.compress(ctop,list(range(0,m.nbpts()))) ftop = m.faces_from_pid(pidtop) TOP = 2 m.set_region(TOP,ftop) # Top-Left points and faces cleft = (abs(allPoints[1,:]) < 1e-6) clefttop=cleft*ctop pidlefttop = np.compress(clefttop,list(range(0,m.nbpts()))) flefttop = m.faces_from_pid(pidlefttop) pidleft = np.compress(cleft,list(range(0,m.nbpts()))) fleft= m.faces_from_pid(pidleft) LEFTTOP = 3 m.set_region(LEFTTOP,flefttop) LEFT = 4 m.set_region(LEFT,fleft) ############################ # Assembly ############################ nbd = mfd.nbdof() # Stiffness matrix sico.Stiff=gf.asm_linear_elasticity(mim, mfu, mfd,np.repeat([Lambda], nbd), np.repeat([Mu], nbd)) # Mass matrix sico.Mass=Rho*gf.asm_mass_matrix(mim, mfu) # Right-hand side Ftop = gf.asm_boundary_source(TOP, mim, mfu, mfd, np.repeat([[0],[0],[-1]],nbd,1)) Fleft= gf.asm_boundary_source(LEFT, mim, mfu, mfd, np.repeat([[0],[10],[0]],nbd,1)) sico.RHS = Ftop + Fleft sico.nbdof = mfu.nbdof() sico.q0 = mfu.basic_dof_from_cvid() sico.bot = pidbot # H-Matrix fillH(pidbot,sico,mfu.nbdof()) return m
def import_fem2(sico): """ Build a mesh object using getfem. We use getfem++ to build the finite element model and to fill in the operators required by siconos: - the mass matrix (Mass) - the stiffness matrix (Stiff) - the matrix that links global coordinates and local coord. at contact points (H) """ ############################ # The geometry and the mesh ############################ dimX = 10.01 dimY = 10.01 dimZ = 10.01 stepX = 1.0 stepY = 1.0 stepZ = 1.0 x = np.arange(0, dimX, stepX) y = np.arange(0, dimY, stepY) z = np.arange(0, dimZ, stepZ) m = gf.Mesh('regular simplices', x, y, z) m.set('optimize_structure') # Export the mesh to vtk m.export_to_vtk("BlockMesh.vtk") # Create MeshFem objects # (i.e. assign elements onto the mesh for each variable) mfu = gf.MeshFem(m, 3) # displacement mfd = gf.MeshFem(m, 1) # data mff = gf.MeshFem(m, 1) # for plot von-mises # assign the FEM mfu.set_fem(gf.Fem('FEM_PK(3,1)')) mfd.set_fem(gf.Fem('FEM_PK(3,0)')) mff.set_fem(gf.Fem('FEM_PK_DISCONTINUOUS(3,1,0.01)')) # mfu.export_to_vtk("BlockMeshDispl.vtk") # Set the integration method mim = gf.MeshIm(m, gf.Integ('IM_TETRAHEDRON(5)')) # Summary print(' ==================================== \n Mesh details: ') print(' Problem dimension:', mfu.qdim(), '\n Number of elements: ', m.nbcvs(), '\n Number of nodes: ', m.nbpts()) print(' Number of dof: ', mfu.nbdof(), '\n Element type: ', mfu.fem()[0].char()) print(' ====================================') ########################### # Set the parameters # for the constitutive law ########################### E = 1e3 # Young modulus Nu = 0.3 # Poisson coef. # Lame coeff. Lambda = E * Nu / ((1 + Nu) * (1 - 2 * Nu)) Mu = E / (2 * (1 + Nu)) # Density Rho = 7800 ############################ # Boundaries detection ############################ allPoints = m.pts() # Bottom points and faces cbot = (abs(allPoints[2, :]) < 1e-6) pidbot = np.compress(cbot, list(range(0, m.nbpts()))) fbot = m.faces_from_pid(pidbot) BOTTOM = 1 m.set_region(BOTTOM, fbot) # Top points and faces ctop = (abs(allPoints[2, :]) > dimZ - stepZ) pidtop = np.compress(ctop, list(range(0, m.nbpts()))) ftop = m.faces_from_pid(pidtop) TOP = 2 m.set_region(TOP, ftop) # Top-Left points and faces cleft = (abs(allPoints[1, :]) < 1e-6) clefttop = cleft * ctop pidlefttop = np.compress(clefttop, list(range(0, m.nbpts()))) flefttop = m.faces_from_pid(pidlefttop) pidleft = np.compress(cleft, list(range(0, m.nbpts()))) fleft = m.faces_from_pid(pidleft) LEFTTOP = 3 m.set_region(LEFTTOP, flefttop) LEFT = 4 m.set_region(LEFT, fleft) ############################ # Assembly ############################ nbd = mfd.nbdof() # Stiffness matrix sico.Stiff = gf.asm_linear_elasticity(mim, mfu, mfd, np.repeat([Lambda], nbd), np.repeat([Mu], nbd)) # Mass matrix sico.Mass = Rho * gf.asm_mass_matrix(mim, mfu) # Right-hand side Ftop = gf.asm_boundary_source(TOP, mim, mfu, mfd, np.repeat([[0], [0], [-1]], nbd, 1)) Fleft = gf.asm_boundary_source(LEFT, mim, mfu, mfd, np.repeat([[0], [10], [0]], nbd, 1)) sico.RHS = Ftop + Fleft sico.nbdof = mfu.nbdof() sico.q0 = mfu.basic_dof_from_cvid() sico.bot = pidbot # H-Matrix fillH(pidbot, sico, mfu.nbdof()) return m