/[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 3025 - (hide annotations)
Thu May 6 01:20:46 2010 UTC (10 years, 3 months ago) by ahallam
File MIME type: text/x-python
File size: 4517 byte(s)
Updates to wave equation examples. Pressure wave examples should be completed now. Working on seismic wave examples. Cookbook chapter for pressure wave examples also added.
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 ahallam 3025 ############################################################FILE HEADER
23     # example07a.py
24 ahallam 3001 # Antony Hallam
25 ahallam 3025 # Acoustic Wave Equation Simulation using displacement solution
26 ahallam 3001
27 ahallam 3025 #######################################################EXTERNAL MODULES
28 ahallam 3001 from esys.escript import *
29     from esys.finley import Rectangle
30     import sys
31     import os
32     # smoothing operator
33 ahallam 3025 from esys.escript.pdetools import Projector, Locator
34     from esys.escript.unitsSI import *
35 ahallam 3001 import numpy as np
36     import pylab as pl
37     import matplotlib.cm as cm
38     from esys.escript.linearPDEs import LinearPDE
39    
40 ahallam 3025 ########################################################MPI WORLD CHECK
41     if getMPISizeWorld() > 1:
42     import sys
43     print "This example will not run in an MPI world."
44     sys.exit(0)
45    
46     #################################################ESTABLISHING VARIABLES
47     # where to save output data
48 ahallam 3001 savepath = "data/example07"
49     mkDir(savepath)
50     #Geometric and material property related variables.
51     mx = 1000. # model lenght
52     my = 1000. # model width
53     ndx = 400 # steps in x direction
54     ndy = 400 # steps in y direction
55 ahallam 3025 xstep=mx/ndx # calculate the size of delta x
56     ystep=my/ndy # calculate the size of delta y
57 ahallam 3001
58 ahallam 3025 c=380.0*m/sec # velocity of sound in air
59     csq=c*c #square of c
60 ahallam 3001 # Time related variables.
61 ahallam 3025 tend=1.5 # end time
62     h=0.001 # time step
63     # data recording times
64     rtime=0.0 # first time to record
65     rtime_inc=tend/20.0 # time increment to record
66 ahallam 3001 #Check to make sure number of time steps is not too large.
67     print "Time step size= ",h, "Expected number of outputs= ",tend/h
68    
69 ahallam 3025 U0=0.005 # amplitude of point source
70     # want a spherical source in the middle of area
71     xc=[500,500] # with reference to mx,my this is the source location
72 ahallam 3001
73 ahallam 3025 ####################################################DOMAIN CONSTRUCTION
74     mydomain=Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy) # create the domain
75     x=mydomain.getX() # get the node locations of the domain
76    
77     ##########################################################ESTABLISH PDE
78     mypde=LinearPDE(mydomain) # create pde
79     mypde.setSymmetryOn() # turn symmetry on
80     mypde.setValue(D=1.) # set the value of D in the general form to 1.
81    
82     ############################################FIRST TIME STEPS AND SOURCE
83 ahallam 3001 # define small radius around point xc
84 ahallam 3003 src_radius = 30
85 ahallam 3001 print "src_radius = ",src_radius
86 ahallam 3025 # set initial values for first two time steps with source terms
87 ahallam 3001 u=U0*(cos(length(x-xc)*3.1415/src_radius)+1)*whereNegative(length(x-xc)-src_radius)
88     u_m1=u
89     #plot source shape
90 ahallam 3025 cut_loc=[] #where the cross section of the source along x will be
91     src_cut=[] #where the cross section of the source will be
92     # create locations for source cross section
93     for i in range(ndx/2-ndx/10,ndx/2+ndx/10):
94     cut_loc.append(xstep*i)
95     src_cut.append([xstep*i,xc[1]])
96     # locate the nearest nodes to the points in src_cut
97     src=Locator(mydomain,src_cut)
98     src_cut=src.getValue(u) #retrieve the values from the nodes
99     # plot the x locations vs value and save the figure
100     pl.plot(cut_loc,src_cut)
101     pl.axis([xc[0]-src_radius*3,xc[0]+src_radius*3,0.,2.*U0])
102 ahallam 3001 pl.savefig(os.path.join(savepath,"source_line.png"))
103    
104 ahallam 3025 ####################################################ITERATION VARIABLES
105     n=0 # iteration counter
106     t=0 # time counter
107     ##############################################################ITERATION
108 ahallam 3001 while t<tend:
109 ahallam 3025 g=grad(u); pres=csq*h*h*g # get current pressure
110     mypde.setValue(X=-pres,Y=(2.*u-u_m1)) # set values in pde
111     u_p1 = mypde.getSolution() # get the new displacement
112     u_m1=u; u=u_p1 # shift values back one time step for next iteration
113     # save current displacement, acceleration and pressure
114     if (t >= rtime):
115     saveVTK(os.path.join(savepath,"ex07b.%i.vtu"%n),displacement=length(u),tensor=pres)
116     rtime=rtime+rtime_inc #increment data save time
117     # increment loop values
118     t=t+h; n=n+1
119 ahallam 3001 print n,"-th time step t ",t

  ViewVC Help
Powered by ViewVC 1.1.26