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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3003 - (show annotations)
Wed Apr 7 02:29:57 2010 UTC (10 years, 4 months ago) by ahallam
File MIME type: text/x-python
File size: 2838 byte(s)
Pressure wave working, accelleration example, new entries to cookbook for example 7.
1
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 # timestep
55 h=0.001
56 #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 xc=[500,500] #location of point source
61
62 mydomain=Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy)
63 x=mydomain.getX()
64 # ... open new PDE ...
65 mypde=LinearPDE(mydomain)
66 print mypde.isUsingLumping()
67 print mypde.getSolverOptions()
68 mypde.setSymmetryOn()
69 mypde.setValue(D=1.)
70 # define small radius around point xc
71 src_radius = 30
72 print "src_radius = ",src_radius
73
74 # ... set initial values ....
75 n=0
76 # for first two time steps
77 u=U0*(cos(length(x-xc)*3.1415/src_radius)+1)*whereNegative(length(x-xc)-src_radius)
78 u_m1=u
79 t=0
80
81 #plot source shape
82 uT=np.array(u.toListOfTuples())
83 uT=np.reshape(uT,(ndx+1,ndy+1))
84 source_line=uT[ndx/2,:]
85 pl.plot(source_line)
86 pl.plot(source_line,'ro')
87 pl.axis([70,130,0,0.05])
88 pl.savefig(os.path.join(savepath,"source_line.png"))
89
90 while t<tend:
91 # get current pressure
92 g=grad(u)
93 pres=csq*h*h*g
94 # set values and calculate solution
95 mypde.setValue(X=-pres,Y=(2.*u-u_m1))
96 u_p1 = mypde.getSolution()
97 # shift displacements
98 u_m1=u; u=u_p1
99 # iteration increments
100 t+=h; n+=1
101 print n,"-th time step t ",t
102 # ... save current acceleration in units of gravity and displacements
103 saveVTK(os.path.join(savepath,"tonysol.%i.vtu"%n),output1 = length(u),tensor=pres)

  ViewVC Help
Powered by ViewVC 1.1.26