ctop = (abs(P[1, :] - 13) < 1e-6) cbot = (abs(P[1, :] + 10) < 1e-6) pidtop = np.compress(ctop, range(0, m.nbpts())) pidbot = np.compress(cbot, range(0, m.nbpts())) ftop = m.faces_from_pid(pidtop) fbot = m.faces_from_pid(pidbot) # create boundary region 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
(mim, "Simo_Miehe", "displacement_and_plastic_multiplier_and_pressure", "u", "ksi", "p", "gamma0", "invCp0", _K_, _mu_, "hardening_law") GAMMA = gf.asm_generic(mim, 1, "gamma*Test_t", -1, "gamma", False, mimd1, md.variable("gamma0"), "t", True, mfout, np.zeros(mfout.nbdof())) GAMMA = np.transpose(gf.linsolve_mumps(mass_mat, GAMMA)) output += (mfout, GAMMA, "plastic strain") mf1.export_to_vtk( '%s/finite_strain_plasticity_%i.vtk' % (resultspath, step), 'ascii', *output) DIRMULT = -md.variable(dirichlet_multname) DIRMULT = np.reshape(DIRMULT, [1, DIRMULT.size]) if symmetric and not rigid_grip: dfR = gf.asm_boundary_source(R_BOUNDARY, mim, mf1, mf_dirichlet_mult, DIRMULT) f.write(('step=%i fR=(%f,0) sR=(%f,0)\n') % (step, dfR.sum(), dfR.sum() / H)) else: dfR = gf.asm_boundary_source(R_BOUNDARY, mim, mfN, mf_dirichlet_mult, DIRMULT) f.write(('step=%i fR=(%f,%f) sR=(%f,%f)\n') % (step, dfR[0::N].sum(), dfR[1::N].sum(), dfR[0::N].sum() / H, dfR[1::N].sum() / H)) f.flush() print('OVERALL SOLUTION TIME IS %f SEC' % (time.process_time() - starttime_overall))
if MM < 1e-4: MM = 0. pseudodynamic = False elif nit <= 6: MM /= 2. else: TMP = md.interpolation("max(psi0_max,psi0)", mimd1, -1) md.set_variable("psi0_max", TMP) break out = (mfu, md.variable("u"), "Displacements", mfphi, md.variable("phi"), "phi") for i, j in [[1, 1], [2, 2], [1, 2]]: sigma = gf.asm_generic(mim, 1, "{sigma}({i},{j})*Test_t".format(sigma=_sigma_, i=i, j=j), -1, md, "t", True, mfout, np.zeros(mfout.nbdof()))\ [md.nbdof():] sigma = np.transpose(gf.linsolve_mumps(mass_mat, sigma)) out += (mfout, sigma, "Cauchy Stress {i}{j}".format(i=i, j=j)) mfout.export_to_vtk("%s/demo_phase_field_%i.vtk" % (resultspath, step), *out) DIRMULT = -md.variable(dirmultname) DIRMULT = np.reshape(DIRMULT, [1, DIRMULT.size]) dfT = gf.asm_boundary_source(T_BOUNDARY, mim, mfu, md.mesh_fem_of_variable(dirmultname), DIRMULT) f.write(("step=%i eps=%e fR=(%e,%e)\n") % (step, eps, dfT[0::N].sum(), dfT[1::N].sum())) f.flush()
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
# 以上で設定した、条件を使用して外力ベクトルと剛性行列を設定します。 # In[16]: help(gf.asm_boundary_source) # In[17]: help(gf.asm_linear_elasticity) # In[18]: nbd = mfd.nbdof() F = gf.asm_boundary_source(NEUMANN_BOUNDARY, mim, mfu, mfd, np.repeat([[0],[-100],[0]],nbd,1)) K = gf.asm_linear_elasticity(mim, mfu, mfd, np.repeat([Lambda], nbd), np.repeat([Mu], nbd)) # # 固定条件の設定 # DIRICHLET条件(固定端条件)の設定をします。 # In[19]: (H,R) = gf.asm_dirichlet(DIRICHLET_BOUNDARY, mim, mfu, mfd, mfd.eval('[[1,0,0],[0,1,0],[0,0,1]]'), mfd.eval('[0,0,0]')) (N,U0) = H.dirichlet_nullspace(R) # In[20]: Nt = gf.Spmat('copy',N)