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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3389 - (hide annotations)
Wed Dec 1 23:03:35 2010 UTC (7 years, 11 months ago) by ahallam
File MIME type: text/x-python
File size: 6397 byte(s)
Some changes to the cookbook examples. Starting Inversion experimentation.
1 ahallam 3389
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     ############################################################FILE HEADER
23     # example09.py
24     # Antony Hallam
25     # Seismic Wave Equation Simulation using acceleration solution.
26     # 3D model with multiple layers.
27    
28     #######################################################EXTERNAL MODULES
29     from esys.escript import *
30     from esys.finley import Rectangle
31     from esys.weipa import saveVTK
32     import os
33     # smoothing operator
34     from esys.escript.pdetools import Projector, Locator
35     from esys.escript.unitsSI import *
36     import numpy as np
37     import matplotlib
38     matplotlib.use('agg') #It's just here for automated testing
39    
40     import pylab as pl
41     import matplotlib.cm as cm
42     from esys.escript.linearPDEs import LinearPDE
43     from esys.finley import ReadMesh
44    
45     ########################################################MPI WORLD CHECK
46     if getMPISizeWorld() > 1:
47     import sys
48     print "This example will not run in an MPI world."
49     sys.exit(0)
50    
51     #################################################ESTABLISHING VARIABLES
52     # where to save output data
53     savepath = "data/example09c"
54     meshpath = "data/example09n"
55     mkDir(savepath)
56     #Geometric and material property related variables.
57     domain=ReadMesh(os.path.join(savepath,'example09n.fly')) # create the domain
58     x=Solution(domain).getX()
59     #parameters layers 1,2,3,4 and fault
60     prho=np.array([2200.,2500.,3200.,4500.,5500.]) #density
61     pvel=np.array([1500.,2200.,3000.,3200.,5000.]) #velocity
62     pmu=pvel**2.*prho/4. #bulk modulus
63     plam=pvel**2.*prho/2. #lames constant
64     nlayers=4
65     width=300.0
66     rho=Scalar(0,Function(domain))
67     vel=Scalar(0,Function(domain))
68     mu=Scalar(0,Function(domain))
69     lam=Scalar(0,Function(domain))
70    
71     print 0.5*np.sqrt(prho/(plam+2*pmu))*0.5
72    
73     for i in range(0,nlayers):
74     rho.setTaggedValue('lblock%d'%i,prho[i])
75     rho.setTaggedValue('rblock%d'%i,prho[i])
76     vel.setTaggedValue('lblock%d'%i,pvel[i])
77     vel.setTaggedValue('rblock%d'%i,pvel[i])
78     mu.setTaggedValue('lblock%d'%i,pmu[i])
79     mu.setTaggedValue('rblock%d'%i,pmu[i])
80     lam.setTaggedValue('lblock%d'%i,plam[i])
81     lam.setTaggedValue('rblock%d'%i,plam[i])
82     i=nlayers
83     rho.setTaggedValue('fault',prho[i])
84     vel.setTaggedValue('fault',pvel[i])
85     mu.setTaggedValue('fault',pmu[i])
86     lam.setTaggedValue('fault',plam[i])
87    
88    
89     # Time related variables.
90     testing=False
91     if testing:
92     print 'The testing end time is currently selected. This severely limits the number of time iterations.'
93     print "Try changing testing to False for more iterations."
94     tend=0.1
95     else:
96     tend=0.1 # end time
97    
98     h=0.00001 # time step
99     # data recording times
100     rtime=0.0 # first time to record
101     rtime_inc=tend/750.0 # time increment to record
102     #Check to make sure number of time steps is not too large.
103     print "Time step size= ",h, "Expected number of outputs= ",tend/h
104    
105     U0=0.1 # amplitude of point source
106     ls=500 # length of the source
107     source=np.zeros(ls,'float') # source array
108     decay1=np.zeros(ls,'float') # decay curve one
109     decay2=np.zeros(ls,'float') # decay curve two
110     time=np.zeros(ls,'float') # time values
111     g=np.log(0.01)/ls
112    
113     dfeq=50 #Dominant Frequency
114     a = 2.0 * (np.pi * dfeq)**2.0
115     t0 = 5.0 / (2.0 * np.pi * dfeq)
116     srclength = 5. * t0
117     ls = int(srclength/h)
118     print 'source length',ls
119     source=np.zeros(ls,'float') # source array
120     ampmax=0
121     for it in range(0,ls):
122     t = it*h
123     tt = t-t0
124     dum1 = np.exp(-a * tt * tt)
125     source[it] = -2. * a * tt * dum1
126     if (abs(source[it]) > ampmax):
127     ampmax = abs(source[it])
128     time[t]=t*h
129    
130     # will introduce a spherical source at middle left of bottom face
131     xc=[150,0]
132    
133     ##########################################################ESTABLISH PDE
134     mypde=LinearPDE(domain) # create pde
135     mypde.setSymmetryOn() # turn symmetry on
136     # turn lumping on for more efficient solving
137     mypde.getSolverOptions().setSolverMethod(mypde.getSolverOptions().HRZ_LUMPING)
138     kmat = kronecker(domain) # create the kronecker delta function of the domain
139     mypde.setValue(D=rho*kmat) #set the general form value D
140    
141     ############################################FIRST TIME STEPS AND SOURCE
142     # define small radius around point xc
143     src_length = 10; print "src_length = ",src_length
144     # set initial values for first two time steps with source terms
145     xb=FunctionOnBoundary(domain).getX()
146     yx=(cos(length(xb-xc)*3.1415/src_length)+1)*whereNegative(length(xb-xc)-src_length)
147     stop=Scalar(0.0,FunctionOnBoundary(domain))
148     stop.setTaggedValue("top",1.0)
149     src_dir=numpy.array([0.,-1.]) # defines direction of point source as down
150    
151     mypde.setValue(y=source[0]*yx*src_dir*stop) #set the source as a function on the boundary
152    
153     # initial value of displacement at point source is constant (U0=0.01)
154     # for first two time steps
155     u=[0.0,0.0]*x
156     u_m1=u
157    
158     ####################################################ITERATION VARIABLES
159     n=0 # iteration counter
160     t=0 # time counter
161     ##############################################################ITERATION
162     while t<tend:
163     # get current stress
164     g=grad(u); stress=lam*trace(g)*kmat+mu*(g+transpose(g))#*abc
165     mypde.setValue(X=-stress) # set PDE values
166     accel = mypde.getSolution() #get PDE solution for accelleration
167     u_p1=(2.*u-u_m1)+h*h*accel #calculate displacement
168     u_p1=u_p1#*abc # apply boundary conditions
169     u_m1=u; u=u_p1 # shift values by 1
170     # save current displacement, acceleration and pressure
171     if (t >= rtime):
172     saveVTK(os.path.join(savepath,"ex09c.%05d.vtu"%n),displacement=length(u),\
173     acceleration=length(accel),tensor=stress)
174     rtime=rtime+rtime_inc #increment data save time
175     # increment loop values
176     t=t+h; n=n+1
177     if (n < ls):
178     mypde.setValue(y=source[n]*yx*src_dir*stop) #set the source as a function on the boundary
179     print n,"-th time step t ",t

  ViewVC Help
Powered by ViewVC 1.1.26