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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3004 - (hide annotations)
Wed Apr 14 05:27:30 2010 UTC (10 years, 3 months ago) by ahallam
File MIME type: text/x-python
File size: 2778 byte(s)
Sampling theorem, stability requirements, Laplacian discussion, Pressure wave PDE
1 ahallam 3001
2     ########################################################
3     #
4     # Copyright (c) 2009-2010 by University of Queensland
5     # Earth Systems Science Computational Center (ESSCC)
6     # http://www.uq.edu.au/esscc
7     #
8     # Primary Business: Queensland, Australia
9     # Licensed under the Open Software License version 3.0
10     # http://www.opensource.org/licenses/osl-3.0.php
11     #
12     ########################################################
13    
14     __copyright__="""Copyright (c) 2009-2010 by University of Queensland
15     Earth Systems Science Computational Center (ESSCC)
16     http://www.uq.edu.au/esscc
17     Primary Business: Queensland, Australia"""
18     __license__="""Licensed under the Open Software License version 3.0
19     http://www.opensource.org/licenses/osl-3.0.php"""
20     __url__="https://launchpad.net/escript-finley"
21    
22     # Antony Hallam
23     # Acoustic Wave Equation Simulation
24    
25     # Importing all the necessary modules required.
26     from esys.escript import *
27     from esys.finley import Rectangle
28     import sys
29     import os
30     # smoothing operator
31     from esys.escript.pdetools import Projector
32     import numpy as np
33     import pylab as pl
34     import matplotlib.cm as cm
35     from esys.escript.linearPDEs import LinearPDE
36    
37     # Establish a save path.
38     savepath = "data/example07"
39     mkDir(savepath)
40    
41     #Geometric and material property related variables.
42     mx = 1000. # model lenght
43     my = 1000. # model width
44     ndx = 400 # steps in x direction
45     ndy = 400 # steps in y direction
46    
47     xstep=mx/ndx
48     ystep=my/ndy
49    
50     c=380.0
51     csq=c*c
52     # Time related variables.
53     tend=1.5 #end time
54 ahallam 3003 # timestep
55     h=0.001
56 ahallam 3001 #Check to make sure number of time steps is not too large.
57     print "Time step size= ",h, "Expected number of outputs= ",tend/h
58    
59     U0=0.01 # amplitude of point source
60 ahallam 3003 xc=[500,500] #location of point source
61 ahallam 3001
62     mydomain=Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
63     x=mydomain.getX()
64     # ... open new PDE ...
65     mypde=LinearPDE(mydomain)
66     mypde.setSymmetryOn()
67 ahallam 3003 mypde.setValue(D=1.)
68 ahallam 3001 # define small radius around point xc
69 ahallam 3003 src_radius = 30
70 ahallam 3001 print "src_radius = ",src_radius
71    
72     # ... set initial values ....
73     n=0
74     # for first two time steps
75     u=U0*(cos(length(x-xc)*3.1415/src_radius)+1)*whereNegative(length(x-xc)-src_radius)
76     u_m1=u
77     t=0
78    
79     #plot source shape
80     uT=np.array(u.toListOfTuples())
81     uT=np.reshape(uT,(ndx+1,ndy+1))
82     source_line=uT[ndx/2,:]
83     pl.plot(source_line)
84     pl.plot(source_line,'ro')
85 ahallam 3003 pl.axis([70,130,0,0.05])
86 ahallam 3001 pl.savefig(os.path.join(savepath,"source_line.png"))
87    
88     while t<tend:
89 ahallam 3003 # get current pressure
90 ahallam 3001 g=grad(u)
91     pres=csq*h*h*g
92 ahallam 3003 # set values and calculate solution
93 ahallam 3001 mypde.setValue(X=-pres,Y=(2.*u-u_m1))
94     u_p1 = mypde.getSolution()
95 ahallam 3003 # shift displacements
96     u_m1=u; u=u_p1
97     # iteration increments
98     t+=h; n+=1
99 ahallam 3001 print n,"-th time step t ",t
100     # ... save current acceleration in units of gravity and displacements
101     saveVTK(os.path.join(savepath,"tonysol.%i.vtu"%n),output1 = length(u),tensor=pres)

  ViewVC Help
Powered by ViewVC 1.1.26