/[escript]/trunk/doc/examples/cookbook/example08b.py
ViewVC logotype

Diff of /trunk/doc/examples/cookbook/example08b.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3891 by ahallam, Wed Dec 8 01:09:06 2010 UTC revision 3892 by jfenwick, Tue Apr 10 08:57:23 2012 UTC
# Line 45  from esys.escript.linearPDEs import Line Line 45  from esys.escript.linearPDEs import Line
45  ########################################################MPI WORLD CHECK  ########################################################MPI WORLD CHECK
46  if getMPISizeWorld() > 1:  if getMPISizeWorld() > 1:
47      import sys      import sys
48      print "This example will not run in an MPI world."      print("This example will not run in an MPI world.")
49      sys.exit(0)      sys.exit(0)
50    
51  #################################################ESTABLISHING VARIABLES  #################################################ESTABLISHING VARIABLES
# Line 65  rho=1154.   #density Line 65  rho=1154.   #density
65  # Time related variables.  # Time related variables.
66  testing=True  testing=True
67  if testing:  if testing:
68      print 'The testing end time is currently selected. This severely limits the number of time iterations.'      print('The testing end time is currently selected. This severely limits the number of time iterations.')
69      print "Try changing testing to False for more iterations."      print("Try changing testing to False for more iterations.")
70      tend=0.001      tend=0.001
71  else:  else:
72      tend=0.5    # end time      tend=0.5    # end time
# Line 76  h=0.0001    # time step Line 76  h=0.0001    # time step
76  rtime=0.0 # first time to record  rtime=0.0 # first time to record
77  rtime_inc=tend/50.0 # time increment to record  rtime_inc=tend/50.0 # time increment to record
78  #Check to make sure number of time steps is not too large.  #Check to make sure number of time steps is not too large.
79  print "Time step size= ",h, "Expected number of outputs= ",tend/h  print("Time step size= ",h, "Expected number of outputs= ",tend/h)
80    
81  U0=0.1 # amplitude of point source  U0=0.1 # amplitude of point source
82  ls=500   # length of the source  ls=500   # length of the source
# Line 91  a = 2.0 * (np.pi * dfeq)**2.0 Line 91  a = 2.0 * (np.pi * dfeq)**2.0
91  t0 = 5.0 / (2.0 * np.pi * dfeq)  t0 = 5.0 / (2.0 * np.pi * dfeq)
92  srclength = 5. * t0  srclength = 5. * t0
93  ls = int(srclength/h)  ls = int(srclength/h)
94  print 'source length',ls  print('source length',ls)
95  source=np.zeros(ls,'float') # source array  source=np.zeros(ls,'float') # source array
96  ampmax=0  ampmax=0
97  for it in range(0,ls):  for it in range(0,ls):
# Line 147  gleft  = calc_gamma(tgamma,bleft) Line 147  gleft  = calc_gamma(tgamma,bleft)
147  gright = calc_gamma(tgamma,bleft)  gright = calc_gamma(tgamma,bleft)
148  gbottom= calc_gamma(tgamma,ystep*bn)  gbottom= calc_gamma(tgamma,ystep*bn)
149    
150  print 'gamma', gleft,gright,gbottom  print('gamma', gleft,gright,gbottom)
151    
152  # calculate decay functions  # calculate decay functions
153  def abc_bfunc(gamma,loc,x,G):  def abc_bfunc(gamma,loc,x,G):
# Line 177  abc=abcleft*abcright*abcbottom Line 177  abc=abcleft*abcright*abcbottom
177    
178  ############################################FIRST TIME STEPS AND SOURCE  ############################################FIRST TIME STEPS AND SOURCE
179  # define small radius around point xc  # define small radius around point xc
180  src_length = 40; print "src_length = ",src_length  src_length = 40; print("src_length = ",src_length)
181  # set initial values for first two time steps with source terms  # set initial values for first two time steps with source terms
182  y=source[0]*(cos(length(x-xc)*3.1415/src_length)+1)*whereNegative(length(x-xc)-src_length)  y=source[0]*(cos(length(x-xc)*3.1415/src_length)+1)*whereNegative(length(x-xc)-src_length)
183  src_dir=numpy.array([0.,1.]) # defines direction of point source as down  src_dir=numpy.array([0.,1.]) # defines direction of point source as down
# Line 211  while t<tend: Line 211  while t<tend:
211      if (n < ls):      if (n < ls):
212          y=source[n]*(cos(length(x-xc)*3.1415/src_length)+1)*whereNegative(length(x-xc)-src_length)          y=source[n]*(cos(length(x-xc)*3.1415/src_length)+1)*whereNegative(length(x-xc)-src_length)
213          y=y*src_dir; mypde.setValue(y=y) #set the source as a function on the boundary          y=y*src_dir; mypde.setValue(y=y) #set the source as a function on the boundary
214      print n,"-th time step t ",t      print(n,"-th time step t ",t)

Legend:
Removed from v.3891  
changed lines
  Added in v.3892

  ViewVC Help
Powered by ViewVC 1.1.26