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

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

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

trunk/doc/examples/cookbook/example07.py revision 3001 by ahallam, Wed Mar 31 04:29:10 2010 UTC trunk/doc/examples/cookbook/example07a.py revision 3003 by ahallam, Wed Apr 7 02:29:57 2010 UTC
# Line 51  c=380.0 Line 51  c=380.0
51  csq=c*c  csq=c*c
52  # Time related variables.  # Time related variables.
53  tend=1.5    #end time  tend=1.5    #end time
54  #calculating )the timestep  # timestep
55  h=tend/1000.  h=0.001
56  #Check to make sure number of time steps is not too large.  #Check to make sure number of time steps is not too large.
57  print "Time step size= ",h, "Expected number of outputs= ",tend/h  print "Time step size= ",h, "Expected number of outputs= ",tend/h
58    
 #uncomment the following lines to give the user a chance to stop  
 #proceeder = raw_input("Is this ok?(y/n)")  
 #Exit if user thinks too many outputs.  
 #if proceeder == "n":  
 #   sys.exit()  
   
59  U0=0.01 # amplitude of point source  U0=0.01 # amplitude of point source
60  #  spherical source at middle of bottom face  xc=[500,500] #location of point source
   
 xc=[500,500]  
61    
62  mydomain=Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)  mydomain=Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
 #wavesolver2d(mydomain,h,tend,lam,mu,rho,U0,xc,savepath,output="mpl")  
63  x=mydomain.getX()  x=mydomain.getX()
   
64  # ... open new PDE ...  # ... open new PDE ...
65  mypde=LinearPDE(mydomain)  mypde=LinearPDE(mydomain)
66  print mypde.isUsingLumping()  print mypde.isUsingLumping()
67  print mypde.getSolverOptions()  print mypde.getSolverOptions()
 #mypde.getSolverOptions().setSolverMethod(mypde.getSolverOptions().LUMPING)  
68  mypde.setSymmetryOn()  mypde.setSymmetryOn()
69  #kmat = kronecker(mydomain)  mypde.setValue(D=1.)
 mypde.setValue(D=1.)#kmat)  
   
70  # define small radius around point xc  # define small radius around point xc
71  # Lsup(x) returns the maximum value of the argument x  src_radius = 30
 src_radius = 30#2*Lsup(domain.getSize())  
72  print "src_radius = ",src_radius  print "src_radius = ",src_radius
73    
74  # ... set initial values ....  # ... set initial values ....
# Line 98  uT=np.reshape(uT,(ndx+1,ndy+1)) Line 84  uT=np.reshape(uT,(ndx+1,ndy+1))
84  source_line=uT[ndx/2,:]  source_line=uT[ndx/2,:]
85  pl.plot(source_line)  pl.plot(source_line)
86  pl.plot(source_line,'ro')  pl.plot(source_line,'ro')
87  pl.axis([70,130,0,0.2])  pl.axis([70,130,0,0.05])
88  pl.savefig(os.path.join(savepath,"source_line.png"))  pl.savefig(os.path.join(savepath,"source_line.png"))
 #~ u_pc_x1 = u_pot[0,0]  
 #~ u_pc_y1 = u_pot[0,1]  
 #~ u_pc_x2 = u_pot[1,0]  
 #~ u_pc_y2 = u_pot[1,1]  
 #~ u_pc_x3 = u_pot[2,0]  
 #~ u_pc_y3 = u_pot[2,1]  
 #~  
 #~ # open file to save displacement at point source  
 #~ u_pc_data=open(os.path.join(savepath,'U_pc.out'),'w')  
 #~ u_pc_data.write("%f %f %f %f %f %f %f\n"%(t,u_pc_x1,u_pc_y1,u_pc_x2,u_pc_y2,u_pc_x3,u_pc_y3))  
89    
90  while t<tend:  while t<tend:
91      # ... get current stress ....      # get current pressure
 #    t=1.  
     ##OLD WAY  
92      g=grad(u)      g=grad(u)
93      pres=csq*h*h*g      pres=csq*h*h*g
94      ### ... get new acceleration ....      # set values and calculate solution
     #mypde.setValue(X=-stress)            
     #a=mypde.getSolution()  
     ### ... get new displacement ...  
     #u_p1=2*u-u_m1+h*h*a  
     ###NEW WAY  
95      mypde.setValue(X=-pres,Y=(2.*u-u_m1))      mypde.setValue(X=-pres,Y=(2.*u-u_m1))
96      u_p1 = mypde.getSolution()      u_p1 = mypde.getSolution()
97      # ... shift displacements ....      # shift displacements
98      u_m1=u      u_m1=u; u=u_p1
99      u=u_p1      # iteration increments
100      #stress =      t+=h; n+=1
     t+=h  
     n+=1  
101      print n,"-th time step t ",t      print n,"-th time step t ",t
     #~ u_pot = cbphones(domain,u,[[300.,200.],[500.,200.],[750.,200.]],2)  
     #~  
     #~ #     print "u at point charge=",u_pc  
     #~ u_pc_x1 = u_pot[0,0]  
     #~ u_pc_y1 = u_pot[0,1]  
     #~ u_pc_x2 = u_pot[1,0]  
     #~ u_pc_y2 = u_pot[1,1]  
     #~ u_pc_x3 = u_pot[2,0]  
     #~ u_pc_y3 = u_pot[2,1]  
   
     # save displacements at point source to file for t > 0  
     #~ u_pc_data.write("%f %f %f %f %f %f %f\n"%(t,u_pc_x1,u_pc_y1,u_pc_x2,u_pc_y2,u_pc_x3,u_pc_y3))  
   
102      # ... save current acceleration in units of gravity and displacements      # ... save current acceleration in units of gravity and displacements
103      saveVTK(os.path.join(savepath,"tonysol.%i.vtu"%n),output1 = length(u),tensor=pres)      saveVTK(os.path.join(savepath,"tonysol.%i.vtu"%n),output1 = length(u),tensor=pres)
   
   
 #~ u_pc_data.close()  
 #~ os.system("mencoder mf://"+savepath+"/*.png -mf type=png:\  
 #~ w=800:h=600:fps=25 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o \  
 #~ wsmpl.avi")  
   
 #mencoder mf://*.png -mf type=png:\w=800:h=600:fps=25 -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o wsmpl.avi  

Legend:
Removed from v.3001  
changed lines
  Added in v.3003

  ViewVC Help
Powered by ViewVC 1.1.26