--- a/interface/tests/python/check_levelset.py +++ b/interface/tests/python/check_levelset.py @@ -82,7 +82,7 @@ m.export_to_pos('m.pos') else: sl = gf.Slice(('none',), mls, 1); - for i in xrange(nbd): + for i in range(nbd): U = np.zeros(nbd) U[i] = 1 sl.export_to_pos('slU'+str(i)+'.pos',mfls,U,'U'+str(i)) --- a/interface/tests/python/demo_dynamic_contact_1D.py +++ b/interface/tests/python/demo_dynamic_contact_1D.py @@ -73,15 +73,15 @@ # Read optional parameters on the command line for i in range(1,len(sys.argv)): exec(sys.argv[i]) -print "Begin experiment for", -if (version == 0): print "Pure Signorini contact", -elif (version == 1): print "Paoli-Schatzman scheme", -elif (version == 2): print "Penalized contact", -elif (version == 3): print "Nitsche's method", -elif (version == 4): print "Taylor-Flanagan method", -print " in P%d, with NX = %d, dt = %g" % (u_degree,NX, dt) +print("Begin experiment for", end=' ') +if (version == 0): print("Pure Signorini contact", end=' ') +elif (version == 1): print("Paoli-Schatzman scheme", end=' ') +elif (version == 2): print("Penalized contact", end=' ') +elif (version == 3): print("Nitsche's method", end=' ') +elif (version == 4): print("Taylor-Flanagan method", end=' ') +print(" in P%d, with NX = %d, dt = %g" % (u_degree,NX, dt)) -if (version == 4 and beta != 0): print 'Incompatibility'; exit(1) +if (version == 4 and beta != 0): print('Incompatibility'); exit(1) # Deduced parameters h = 1./NX @@ -90,8 +90,8 @@ dt_max_approx = h/(2* u_degree); if (version == 2): dt_max_approx = min(dt_max_approx, 2*h/(gamma0_P)) if (version == 3): dt_max_approx = min(dt_max_approx, 2*h/(gamma0_N)) -print 'Approximative dt_max for CFL :', dt_max_approx -if (beta == 0 and dt > dt_max_approx): print 'Time step too large'; exit(1) +print('Approximative dt_max for CFL :', dt_max_approx) +if (beta == 0 and dt > dt_max_approx): print('Time step too large'); exit(1) # Exact solution. The solution is periodic of period 3 # Return the displacement (d=0), x derivative (d=1) or time derivative (d=2) @@ -377,8 +377,8 @@ # Draw the approximated and exact solutions if (t >= tplot-(1e-10)): tplot += dtplot; - print ("Time %3f"% t), "/", T, - print (" Energy %7f" % E), (" Mech energy %7f" % E_org) + print(("Time %3f"% t), "/", T, end=' ') + print((" Energy %7f" % E), (" Mech energy %7f" % E_org)) if (do_inter_plot): UUex = np.copy(Xdraw) @@ -407,23 +407,23 @@ # print the main relative errors LinfL2u = np.amax(store_UL2) / np.amax(store_UL2_ex) -print 'L^\intfy(0,T,L^2)-norm of the error on u: ', LinfL2u +print('L^\intfy(0,T,L^2)-norm of the error on u: ', LinfL2u) LinfH1u = np.amax(store_UH1) / np.amax(store_UH1_ex) -print 'L^\intfy(0,T,H^1)-norm of the error on u: ', LinfH1u +print('L^\intfy(0,T,H^1)-norm of the error on u: ', LinfH1u) LinfL2v = np.amax(store_VL2) / np.amax(store_VL2_ex) -print 'L^\intfy(0,T,L^2)-norm of the error on v: ', LinfL2v +print('L^\intfy(0,T,L^2)-norm of the error on v: ', LinfL2v) Nor = np.sqrt(np.sum(np.square(store_UL2_ex))*dt) L2L2u = np.sqrt(np.sum(np.square(store_UL2))*dt) / Nor -print 'L^2(0,T,L^2)-norm of the error on u: ', L2L2u +print('L^2(0,T,L^2)-norm of the error on u: ', L2L2u) Nor = np.sqrt(np.sum(np.square(store_UH1_ex))*dt) L2H1u = np.sqrt(np.sum(np.square(store_UH1))*dt) / Nor -print 'L^2(0,T,H^1)-norm of the error on u: ', L2H1u +print('L^2(0,T,H^1)-norm of the error on u: ', L2H1u) Nor = np.sqrt(np.sum(np.square(store_VL2_ex))*dt) L2L2v = np.sqrt(np.sum(np.square(store_VL2))*dt) / Nor -print 'L^2(0,T)-norm of the error on v: ', L2L2v +print('L^2(0,T)-norm of the error on v: ', L2L2v) Nor = np.sqrt(np.sum(np.square(store_s0_ex))*dt) L2sn = np.sqrt(np.sum(np.square(store_s0-store_s0_ex))*dt) / Nor -print 'L^2(0,T)-norm of the error on contact stress: ', L2sn +print('L^2(0,T)-norm of the error on contact stress: ', L2sn) if (do_export_in_files): --- a/interface/tests/python/demo_mortar.py +++ b/interface/tests/python/demo_mortar.py @@ -90,7 +90,7 @@ expr = 'M(#1,#2)+=comp(vBase(#1).vBase(#2))(:,i,:,i)' M = gf.asm_boundary(MORTAR_BOUNDARY_IN, expr, mim, mfm, mfu) M = M-gf.asm_boundary(MORTAR_BOUNDARY_OUT, expr, mim, mfm, mfu) -M = gf.Spmat('copy', M, indm, range(M.size()[1])) +M = gf.Spmat('copy', M, indm, list(range(M.size()[1]))) md = gf.Model('real') md.add_fem_variable('u', mfu); --- a/interface/tests/python/demo_plasticity.py +++ b/interface/tests/python/demo_plasticity.py @@ -65,8 +65,8 @@ sigma_y=4000 P=m.pts() -pidleft=np.compress((abs(P[0,:])<1e-6), range(0, m.nbpts())) -pidright=np.compress((abs(P[0,:] - L)<1e-6), range(0, m.nbpts())) +pidleft=np.compress((abs(P[0,:])<1e-6), list(range(0, m.nbpts()))) +pidright=np.compress((abs(P[0,:] - L)<1e-6), list(range(0, m.nbpts()))) fleft = m.faces_from_pid(pidleft) fright = m.faces_from_pid(pidright) --- a/interface/tests/python/demo_stokes_3D_tank.py +++ b/interface/tests/python/demo_stokes_3D_tank.py @@ -46,7 +46,7 @@ P=m.pts() -r = range(0, m.nbpts()); +r = list(range(0, m.nbpts())); INpid=compress(abs(P[0,:]+25) < 1e-4, r) OUTpid=compress(abs(P[0,:]-25) < 1e-4, r) TOPpid=compress(abs(P[2,:]-20) < 1e-4, r) @@ -73,7 +73,7 @@ md.add_linear_incompressibility_brick(mim, 'u', 'p'); md.add_variable('mult_spec', 1); M = Spmat('empty', 1, mfp.nbdof()); -M.add(range(1), range(mfp.nbdof()), ones((1, mfp.nbdof()))); +M.add(list(range(1)), list(range(mfp.nbdof())), ones((1, mfp.nbdof()))); md.add_constraint_with_multipliers('p', 'mult_spec', M, [0]); md.add_initialized_data('NeumannData', [0, -10, 0]); md.add_source_term_brick(mim, 'u', 'NeumannData', 1); --- a/interface/tests/python/demo_tripod.py +++ b/interface/tests/python/demo_tripod.py @@ -62,8 +62,8 @@ print('test', P[1,:]) 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())) +pidtop=np.compress(ctop, list(range(0, m.nbpts()))) +pidbot=np.compress(cbot, list(range(0, m.nbpts()))) ftop=m.faces_from_pid(pidtop) fbot=m.faces_from_pid(pidbot) --- a/interface/tests/python/demo_tripod_alt.py +++ b/interface/tests/python/demo_tripod_alt.py @@ -50,8 +50,8 @@ ctop=(abs(P[1,:] - 13) < 1e-6); cbot=(abs(P[1,:] + 10) < 1e-6); -pidtop=compress(ctop, range(0, m.nbpts())) -pidbot=compress(cbot, range(0, m.nbpts())) +pidtop=compress(ctop, list(range(0, m.nbpts()))) +pidbot=compress(cbot, list(range(0, m.nbpts()))) ftop=m.faces_from_pid(pidtop) fbot=m.faces_from_pid(pidbot) --- a/interface/tests/python/demo_wave.py +++ b/interface/tests/python/demo_wave.py @@ -52,8 +52,8 @@ Psqr=sum(P*P, 0); cobj=(Psqr < 1*1+1e-6); cout=(Psqr > 10*10-1e-2); -pidobj=compress(cobj, range(0, m.nbpts())) -pidout=compress(cout, range(0, m.nbpts())) +pidobj=compress(cobj, list(range(0, m.nbpts()))) +pidout=compress(cout, list(range(0, m.nbpts()))) fobj=m.faces_from_pid(pidobj) fout=m.faces_from_pid(pidout) ROBIN_BOUNDARY = 1 --- a/interface/tests/python/getfem_tvtk.py +++ b/interface/tests/python/getfem_tvtk.py @@ -173,7 +173,7 @@ elif (len(data) == 1): U = data[0] else: - raise Exception, "wrong data tuple.." + raise Exception("wrong data tuple..") else: U = data if mf is not None: @@ -196,7 +196,7 @@ d = self.dfield_on_slice(vdata) n = self.sl.nbpts() if d.size % n != 0: - raise Exception, "non consistent dimension for data" + raise Exception("non consistent dimension for data") if d.size > n: d = d.transpose() d.shape = (n,-1) @@ -230,7 +230,7 @@ elif isinstance(c, tvtk.LookupTable): lut = c else: - raise Exception, "expected a string or a tvtk.LookupTable" + raise Exception("expected a string or a tvtk.LookupTable") self.lookup_table = lut if (self.mapper is not None): self.mapper.lookup_table = self.lookup_table @@ -276,7 +276,7 @@ elif self.glyph_name == 'cube': glyph.source = tvtk.CubeSource().output else: - raise Exception, "Unknown glyph name.." + raise Exception("Unknown glyph name..") #glyph.scaling = 1 #glyph.scale_factor = self.glyph_scale_factor data = glyph.output @@ -394,16 +394,16 @@ def show_mesh_fem(self, mf, **args): it = FigureItem(self) it.build_from_mesh(mf.linked_mesh(), **args) - if args.has_key('deformation'): + if 'deformation' in args: it.deformation_from_mf(args.get('deformation_mf',mf), args['deformation'], args.get('deformation_scale','10%')); - if args.has_key('data'): + if 'data' in args: it.set_scalar_data(args.get('data'), args.get('scalar_label', 'data')); it.set_scalar_bar(args.get('scalar_bar', False)) - if args.has_key('vdata'): + if 'vdata' in args: it.set_vector_data(args.get('vdata')) self.actors += it.vtk_actors() @@ -415,13 +415,13 @@ it = FigureItem(self) it.build_from_slice(sl, **args) - if args.has_key('data'): + if 'data' in args: it.set_scalar_data(args.get('data'), args.get('scalar_label', 'data')); it.set_scalar_bar(args.get('scalar_bar', False)) - if args.has_key('vdata'): + if 'vdata' in args: it.set_vector_data(args.get('vdata')) self.actors += it.vtk_actors() @@ -437,7 +437,7 @@ for i in self.items: i.scalar_range(*args) else: - raise Exception, "plot something before changing its scalar range!" + raise Exception("plot something before changing its scalar range!") ## def scalar_bar(self): ## if len(self.items): @@ -454,7 +454,7 @@ elif isinstance(mf, getfem.Slice): self.show_slice(mf, **args) else: - raise TypeError, "argument must be a drawable getfem object" + raise TypeError("argument must be a drawable getfem object") def loop(self): for a in self.actors: self.renderer.add_actor(a)