[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Getfem-commits] [getfem-commits] branch fixmisspell updated: Update cod
From: |
Tetsuo Koyama |
Subject: |
[Getfem-commits] [getfem-commits] branch fixmisspell updated: Update code samples from Python2 format to Python3 |
Date: |
Tue, 18 Apr 2023 04:31:48 -0400 |
This is an automated email from the git hooks/post-receive script.
tkoyama010 pushed a commit to branch fixmisspell
in repository getfem.
The following commit(s) were added to refs/heads/fixmisspell by this push:
new 07809d94 Update code samples from Python2 format to Python3
07809d94 is described below
commit 07809d94e67f5e783ddb628a90205a278a45c682
Author: Tetsuo Koyama <tkoyama010@gmail.com>
AuthorDate: Tue Apr 18 17:26:40 2023 +0900
Update code samples from Python2 format to Python3
---
.../python/code_samples/demo_fictitious_domains.py | 11 +++---
.../source/python/code_samples/demo_laplacian.py | 6 ++--
.../python/code_samples/demo_step_by_step.py | 2 +-
.../source/python/code_samples/demo_tripod.py | 2 +-
.../source/python/code_samples/demo_tripod_alt.py | 42 +++++++++++-----------
5 files changed, 32 insertions(+), 31 deletions(-)
diff --git a/doc/sphinx/source/python/code_samples/demo_fictitious_domains.py
b/doc/sphinx/source/python/code_samples/demo_fictitious_domains.py
index a6c6699f..1a549a87 100644
--- a/doc/sphinx/source/python/code_samples/demo_fictitious_domains.py
+++ b/doc/sphinx/source/python/code_samples/demo_fictitious_domains.py
@@ -3,7 +3,8 @@ This demo use levelset to impose (weakly) a Dirichlet condition
on an
implicit boundary defined by the zero of the levelset
"""
import numpy as np
-from scipy import rand, setdiff1d
+from numpy.random import rand
+from numpy import setdiff1d
import getfem as gf
@@ -25,8 +26,8 @@ ULS = 1000*np.ones((1,x.size))
if 0:
- for ix in xrange(5):
- for iy in xrange(5):
+ for ix in range(5):
+ for iy in range(5):
xc = (ix/4) * 0.8 - 0.4
yc = (iy/4) * 0.8 - 0.4
if iy%2==0:
@@ -36,7 +37,7 @@ if 0:
R = 0.03 + 0.005*(iy-1)
ULS = np.minimum(ULS, ((x - xc)**2 + (y - yc)**2) - R**2)
else:
- for i in xrange(8):
+ for i in range(8):
xc = rand() - 0.5
yc = rand() - 0.5
R = rand() * 0.09 + 0.02
@@ -47,7 +48,7 @@ ls.set_values(ULS)
ULS2 = 1000*np.ones((1,x.size));
ULS2s = 1000*np.ones((1,x.size));
-for i in xrange(1):
+for i in range(1):
xc = 0 # rand() - 0.5
yc = 0 # rand() - 0.5
theta = np.pi/3 #np.pi*rand()
diff --git a/doc/sphinx/source/python/code_samples/demo_laplacian.py
b/doc/sphinx/source/python/code_samples/demo_laplacian.py
index 2827f706..3c2b5fe1 100644
--- a/doc/sphinx/source/python/code_samples/demo_laplacian.py
+++ b/doc/sphinx/source/python/code_samples/demo_laplacian.py
@@ -114,9 +114,9 @@ L2error = gf.compute(mfu, u-g, 'L2 norm', mim)
H1error = gf.compute(mfu, u-g, 'H1 norm', mim)
if (H1error > 1e-3):
- print 'Error in L2 norm : ', L2error
- print 'Error in H1 norm : ', H1error
- print 'Error too large !'
+ print('Error in L2 norm : ', L2error)
+ print('Error in H1 norm : ', H1error)
+ print('Error too large !')
# export data
mfu.export_to_pos('sol.pos', g,'Exact solution',
diff --git a/doc/sphinx/source/python/code_samples/demo_step_by_step.py
b/doc/sphinx/source/python/code_samples/demo_step_by_step.py
index 66d06d3c..26d0175d 100644
--- a/doc/sphinx/source/python/code_samples/demo_step_by_step.py
+++ b/doc/sphinx/source/python/code_samples/demo_step_by_step.py
@@ -15,7 +15,7 @@ mf = gf.MeshFem(m, 1)
mf.set_fem(gf.Fem('FEM_QK(2,2)'))
# view the expression of its basis functions on the reference convex
-print gf.Fem('FEM_QK(2,2)').poly_str()
+print(gf.Fem('FEM_QK(2,2)').poly_str())
# an exact integration will be used
mim = gf.MeshIm(m, gf.Integ('IM_EXACT_PARALLELEPIPED(2)'))
diff --git a/doc/sphinx/source/python/code_samples/demo_tripod.py
b/doc/sphinx/source/python/code_samples/demo_tripod.py
index 056fa74a..4adadde8 100644
--- a/doc/sphinx/source/python/code_samples/demo_tripod.py
+++ b/doc/sphinx/source/python/code_samples/demo_tripod.py
@@ -42,7 +42,7 @@ except:
with_graphics=False
-m=gf.Mesh('import','gid','../meshes/tripod.GiD.msh')
+m=gf.Mesh('import','gid','tripod.GiD.msh')
print('done!')
mfu=gf.MeshFem(m,3) # displacement
mfp=gf.MeshFem(m,1) # pressure
diff --git a/doc/sphinx/source/python/code_samples/demo_tripod_alt.py
b/doc/sphinx/source/python/code_samples/demo_tripod_alt.py
index 968d3d17..5299a2a4 100644
--- a/doc/sphinx/source/python/code_samples/demo_tripod_alt.py
+++ b/doc/sphinx/source/python/code_samples/demo_tripod_alt.py
@@ -31,8 +31,8 @@ mfe.set_fem(gf.Fem('FEM_PK_DISCONTINUOUS(3,%d,0.01)' %
(degree,)))
# build a MeshIm object
mim = gf.MeshIm(m, gf.Integ('IM_TETRAHEDRON(5)'))
-print 'nbcvs=%d, nbpts=%d, qdim=%d, fem = %s, nbdof=%d' % \
- (m.nbcvs(), m.nbpts(), mfu.qdim(), mfu.fem()[0].char(), mfu.nbdof())
+print('nbcvs=%d, nbpts=%d, qdim=%d, fem = %s, nbdof=%d' % \
+ (m.nbcvs(), m.nbpts(), mfu.qdim(), mfu.fem()[0].char(), mfu.nbdof()))
# detect some boundary of the mesh
P = m.pts()
@@ -50,27 +50,27 @@ m.set_region(DIRICHLET_BOUNDARY,fbot)
# assembly
nbd = mfd.nbdof()
-print "nbd: ",nbd
+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
+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
+print("K.display(): ",K.display()) # 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('identity(3)'), mfd.eval('[0,0,0]'))
-print "H.info: ",H.info # Spmat instance
-print "R.shape: ",R.shape
-print "mfd.eval('identity(3)').shape: ",mfd.eval('identity(3)').shape
-print "mfd.eval('[0,0,0]').shape: ",mfd.eval('[0,0,0]').shape
+(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]'))
+print("H.display(): ",H.display()) # Spmat instance
+print("R.shape: ",R.shape)
+print("mfd.eval('[[1,0,0], [0,1,0], [0,0,1]]').shape: ",mfd.eval('[[1,0,0],
[0,1,0], [0,0,1]]').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
-print "U0.shape: ",U0.shape
+print("N.display(): ",N.display()) # Spmat instance
+print("U0.shape: ",U0.shape)
Nt = gf.Spmat('copy',N)
Nt.transpose()
@@ -80,9 +80,9 @@ FF = Nt*F # FF = Nt*(F-K*U0)
# solve ...
P = gf.Precond('ildlt',KK)
UU = gf.linsolve_cg(KK,FF,P)
-print "UU.shape:",UU.shape
+print("UU.shape:",UU.shape)
U = N*UU+U0
-print "U.shape:",U.shape
+print("U.shape:",U.shape)
# post-processing
sl = gf.Slice(('boundary',), mfu, degree)
@@ -98,7 +98,7 @@ for i in range(DU.shape[2]):
Sigma[:,:,i]=E
VM[i] = np.sum(E**2) - (1./3.)*np.sum(np.diagonal(E))**2
-print 'Von Mises range: ', VM.min(), VM.max()
+print('Von Mises range: ', VM.min(), VM.max())
# export results to VTK (you can use http://mayavi.sourceforge.net/ to view
these results )
# i.e. with "mayavi -d tripod.vtk -m BandedSurfaceMap -f WarpVector"
@@ -114,8 +114,8 @@ print 'Von Mises range: ', VM.min(), VM.max()
SigmaSL = gf.compute_interpolate_on(mfe,Sigma,sl)
#sl.export_to_vtk('tripod_ev.vtk', mfu, U, 'Displacement', SigmaSL, 'stress')
-#print 'You can view the tripod with (for example) mayavi:'
-#print 'mayavi -d ./tripod.vtk -f WarpVector -m BandedSurfaceMap'
+#print('You can view the tripod with (for example) mayavi:')
+#print('mayavi -d ./tripod.vtk -f WarpVector -m BandedSurfaceMap')
# export to Gmsh
sl.export_to_pos('tripod.pos', mfe, VM,'Von Mises Stress', mfu, U,
'Displacement')
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Getfem-commits] [getfem-commits] branch fixmisspell updated: Update code samples from Python2 format to Python3,
Tetsuo Koyama <=