/[escript]/trunk/finley/test/python/seismic_wave.py
ViewVC logotype

Contents of /trunk/finley/test/python/seismic_wave.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1965 - (show annotations)
Wed Nov 5 03:24:09 2008 UTC (10 years, 10 months ago) by caltinay
File MIME type: text/x-python
File size: 11863 byte(s)
Fixed working directory of the seismic_wave example.

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 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) 2003-2008 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__="http://www.uq.edu.au/esscc/escript-finley"
21
22 """
23 seismic wave propagation
24
25 @var __author__: name of author
26 @var __licence__: licence agreement
27 @var __url__: url entry point on documentation
28 @var __version__: version
29 @var __date__: date of the version
30 """
31
32 __author__="Lutz Gross, l.gross@uq.edu.au"
33
34 from esys.escript import *
35 from esys.escript.linearPDEs import LinearPDE
36 from esys.finley import Brick
37 import time
38
39 WORKDIR="./waves/"
40 output=True
41 n_end=10000
42
43 resolution=1000. # number of elements per m in the finest region
44 resolution=400. # number of elements per m in the finest region
45 o=1 # element order
46
47 l=100000. # width and length m (without obsorber)
48 h=30000. # height in m (without obsorber)
49 d_absorber=l*0.10 # thickness of absorbing layer
50
51 l_sand=20000. # thickness of sand region on surface
52 h_sand=5000. # thickness of sand layer under the water
53
54 l_x_water=10000. # length of water in x
55 l_y_water=10000. # length of water in y
56 h_water=2000. # depth of water region
57
58 x_sand=l/2-l_x_water/2-l_sand # x coordinate of location of sand region (without obsorber)
59 y_sand=l/2-l_y_water/2-l_sand # y coordinate of location of sand region (without obsorber)
60
61
62 # origin
63 origin={"x": -d_absorber, "y" : -d_absorber , "z" : -h-d_absorber }
64 # location and geometrical size of event reltive to origin:
65 xc=[l*0.2,l*0.3,-h*0.7]
66 src_radius = 2*resolution
67 # direction of event:
68 event=numarray.array([0.,0.,1.])*1.e6
69 # time and length of the event
70 tc=2.
71 tc_length=0.5
72
73 # material properties:
74 bedrock=0
75 absorber=1
76 water=2
77 sand=3
78
79 rho_tab={}
80 rho_tab[bedrock]=8e3
81 rho_tab[absorber]=rho_tab[bedrock]
82 rho_tab[water]=1e3
83 rho_tab[sand]=5e3
84
85 mu_tab={}
86 mu_tab[bedrock]=1.7e11
87 mu_tab[absorber]=mu_tab[bedrock]
88 mu_tab[water]=0.
89 mu_tab[sand]=1.5e10
90
91 lmbd_tab={}
92 lmbd_tab[bedrock]=1.7e11
93 lmbd_tab[absorber]=lmbd_tab[bedrock]
94 lmbd_tab[water]=1.e9
95 lmbd_tab[sand]=1.5e10
96
97 eta_tab={}
98 eta_tab[absorber]=-log(0.05)*sqrt(rho_tab[absorber]*(lmbd_tab[absorber]+2*mu_tab[absorber]))/d_absorber
99 eta_tab[sand]=eta_tab[absorber]/40.
100 eta_tab[water]=eta_tab[absorber]/40.
101 eta_tab[bedrock]=eta_tab[absorber]/40.
102
103
104 # material properties:
105 bedrock=0
106 absorber=1
107 water=2
108 sand=3
109
110 rho={}
111 rho[bedrock]=8e3
112 rho[absorber]=rho[bedrock]
113 rho[water]=1e3
114 rho[sand]=5e3
115
116 mu={}
117 mu[bedrock]=1.7e11
118 mu[absorber]=mu[bedrock]
119 mu[water]=0.
120 mu[sand]=1.5e10
121
122 lmbd={}
123 lmbd[bedrock]=1.7e11
124 lmbd_absorber=lmbd[bedrock]
125 lmbd[water]=1.e9
126 lmbd[sand]=1.5e10
127
128 eta={}
129 eta[absorber]=-log(0.05)*sqrt(rho[absorber]*(lmbd_absorber+2*mu[absorber]))/d_absorber
130 eta[sand]=eta[absorber]/40.
131 eta[water]=eta[absorber]/40.
132 eta[bedrock]=eta[absorber]/40.
133
134 if output:
135 print "event location = ",xc
136 print "radius of event = ",src_radius
137 print "time of event = ",tc
138 print "length of event = ",tc_length
139 print "direction = ",event
140
141 t_end=30.
142 dt_write=0.1
143
144
145 def getDomain():
146 """
147 this defines a dom as a brick of length and width l and hight h
148
149
150 """
151 global netotal
152
153 v_p={}
154 for tag in rho_tab.keys():
155 v_p[tag]=sqrt((2*mu_tab[tag]+lmbd_tab[tag])/rho_tab[tag])
156 v_p_ref=min(v_p.values())
157 print "velocities: bedrock = %s, sand = %s, water =%s, absorber =%s, reference =%s"%(v_p[bedrock],v_p[sand],v_p[water],v_p[absorber],v_p_ref)
158
159 sections={}
160 sections["x"]=[d_absorber, x_sand, l_sand, l_x_water, l_sand, l-x_sand-2*l_sand-l_x_water, d_absorber]
161 sections["y"]=[d_absorber, y_sand, l_sand, l_y_water, l_sand, l-y_sand-2*l_sand-l_y_water, d_absorber]
162 sections["z"]=[d_absorber,h-h_water-h_sand,h_sand,h_water]
163 if output:
164 print "sections x = ",sections["x"]
165 print "sections y = ",sections["y"]
166 print "sections z = ",sections["z"]
167
168 mats= [
169 [ [absorber, absorber, absorber, absorber, absorber, absorber, absorber],
170 [absorber, absorber, absorber, absorber, absorber, absorber, absorber],
171 [absorber, absorber, absorber, absorber, absorber, absorber, absorber],
172 [absorber, absorber, absorber, absorber, absorber, absorber, absorber],
173 [absorber, absorber, absorber, absorber, absorber, absorber, absorber],
174 [absorber, absorber, absorber, absorber, absorber, absorber, absorber],
175 [absorber, absorber, absorber, absorber, absorber, absorber, absorber] ],
176
177 [ [absorber, absorber, absorber, absorber, absorber, absorber, absorber],
178 [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber],
179 [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber],
180 [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber],
181 [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber],
182 [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber],
183 [absorber, absorber, absorber, absorber, absorber, absorber, absorber] ],
184
185 [ [absorber, absorber, absorber, absorber, absorber, absorber, absorber],
186 [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber],
187 [absorber, bedrock , sand , sand , sand , bedrock , absorber],
188 [absorber, bedrock , sand , sand , sand , bedrock , absorber],
189 [absorber, bedrock , sand , sand , sand , bedrock , absorber],
190 [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber],
191 [absorber, absorber, absorber, absorber, absorber, absorber, absorber] ],
192
193 [ [absorber, absorber, absorber, absorber, absorber, absorber, absorber],
194 [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber],
195 [absorber, bedrock , sand , sand , sand , bedrock , absorber],
196 [absorber, bedrock , sand , water , sand , bedrock , absorber],
197 [absorber, bedrock , sand , sand , sand , bedrock , absorber],
198 [absorber, bedrock , bedrock , bedrock , bedrock , bedrock , absorber],
199 [absorber, absorber, absorber, absorber, absorber, absorber, absorber] ] ]
200
201 num_elem={}
202 for d in sections:
203 num_elem[d]=[]
204 for i in range(len(sections[d])):
205 if d=="x":
206 v_p_min=v_p[mats[0][0][i]]
207 for q in range(len(sections["y"])):
208 for r in range(len(sections["z"])):
209 v_p_min=min(v_p[mats[r][q][i]],v_p_min)
210 elif d=="y":
211 v_p_min=v_p[mats[0][i][0]]
212 for q in range(len(sections["x"])):
213 for r in range(len(sections["z"])):
214 v_p_min=min(v_p[mats[r][i][q]],v_p_min)
215 elif d=="z":
216 v_p_min=v_p[mats[i][0][0]]
217 for q in range(len(sections["x"])):
218 for r in range(len(sections["y"])):
219 v_p_min=min(v_p[mats[i][r][q]],v_p_min)
220 num_elem[d].append(max(1,int(sections[d][i] * v_p_ref/v_p_min /resolution+0.5)))
221
222 ne_x=sum(num_elem["x"])
223 ne_y=sum(num_elem["y"])
224 ne_z=sum(num_elem["z"])
225 netotal=ne_x*ne_y*ne_z
226 if output: print "grid : %s x %s x %s (%s elements)"%(ne_x,ne_y,ne_z,netotal)
227 dom=Brick(ne_x,ne_y,ne_z,l0=o*ne_x,l1=o*ne_y,l2=o*ne_z,order=o)
228 x_old=dom.getX()
229 x_new=0
230
231 for d in sections:
232 if d=="x":
233 i=0
234 f=[1,0,0]
235 if d=="y":
236 i=1
237 f=[0,1,0]
238 if d=="z":
239 i=2
240 f=[0,0,1]
241 x=x_old[i]
242
243 p=origin[d]
244 ne=0
245 s=0.
246
247 for i in range(len(sections[d])-1):
248 msk=whereNonPositive(x-o*ne+0.5)
249 s=s*msk + (sections[d][i]/(o*num_elem[d][i])*(x-o*ne)+p)*(1.-msk)
250 ne+=num_elem[d][i]
251 p+=sections[d][i]
252 x_new=x_new + s * f
253 dom.setX(x_new)
254
255 fs=Function(dom)
256 x=Function(dom).getX()
257 x0=x[0]
258 x1=x[1]
259 x2=x[2]
260 p_z=origin["z"]
261 for i in range(len(mats)):
262 f_z=wherePositive(x2-p_z)*wherePositive(x2-p_z+sections["z"][i])
263 p_y=origin["y"]
264 for j in range(len(mats[i])):
265 f_y=wherePositive(x1-p_y)*wherePositive(x1-p_z+sections["y"][j])
266 p_x=origin["x"]
267 for k in range(len(mats[i][j])):
268 f_x=wherePositive(x0-p_x)*wherePositive(x0-p_x+sections["x"][k])
269 fs.setTags(mats[i][j][k],f_x*f_y*f_z)
270 p_x+=sections["x"][k]
271 p_y+=sections["y"][j]
272 p_z+=sections["z"][i]
273 return dom
274
275 def getMaterialProperties(dom):
276 rho =Scalar(rho_tab[bedrock],Function(dom))
277 eta =Scalar(eta_tab[bedrock],Function(dom))
278 mu =Scalar(mu_tab[bedrock],Function(dom))
279 lmbd=Scalar(lmbd_tab[bedrock],Function(dom))
280 tags=Scalar(bedrock,Function(dom))
281
282 for tag in rho_tab.keys():
283 rho.setTaggedValue(tag,rho_tab[tag])
284 eta.setTaggedValue(tag,eta_tab[tag])
285 mu.setTaggedValue(tag,mu_tab[tag])
286 lmbd.setTaggedValue(tag,lmbd_tab[tag])
287 tags.setTaggedValue(tag,tag)
288 return rho,mu,lmbd,eta
289
290 def wavePropagation(dom,rho,mu,lmbd,eta):
291 x=Function(dom).getX()
292 # ... open new PDE ...
293 mypde=LinearPDE(dom)
294 mypde.setSolverMethod(LinearPDE.LUMPING)
295 k=kronecker(Function(dom))
296 mypde.setValue(D=k*rho)
297
298 dt=(1./5.)*inf(dom.getSize()/sqrt((2*mu+lmbd)/rho))
299 if output: print "time step size = ",dt
300 # ... set initial values ....
301 n=0
302 t=0
303 t_write=0.
304 n_write=0
305 # initial value of displacement at point source is constant (U0=0.01)
306 # for first two time steps
307 u=Vector(0.,Solution(dom))
308 v=Vector(0.,Solution(dom))
309 a=Vector(0.,Solution(dom))
310 a2=Vector(0.,Solution(dom))
311 v=Vector(0.,Solution(dom))
312
313 if not os.path.isdir(WORKDIR): os.mkdir(WORKDIR)
314
315 starttime = time.clock()
316 while t<t_end and n<n_end:
317 if output: print n+1,"-th time step t ",t+dt," max u and F: ",Lsup(u),
318 # prediction:
319 u_pr=u+dt*v+(dt**2/2)*a+(dt**3/6)*a2
320 v_pr=v+dt*a+(dt**2/2)*a2
321 a_pr=a+dt*a2
322 # ... get current stress ....
323 eps=symmetric(grad(u_pr))
324 stress=lmbd*trace(eps)*k+2*mu*eps
325 # ... force due to event:
326 if abs(t-tc)<5*tc_length:
327 F=exp(-((t-tc)/tc_length)**2)*exp(-(length(x-xc)/src_radius)**2)*event
328 if output: print Lsup(F)
329 else:
330 if output: print 0.
331 # ... get new acceleration ....
332 mypde.setValue(X=-stress,Y=F-eta*v_pr)
333 a=mypde.getSolution()
334 # ... get new displacement ...
335 da=a-a_pr
336 u=u_pr+(dt**2/12.)*da
337 v=v_pr+(5*dt/12.)*da
338 a2+=da/dt
339 # ... save current acceleration in units of gravity and displacements
340 if output:
341 if t>=t_write:
342 saveVTK(WORKDIR+"disp.%i.vtu"%n_write,displacement=u, amplitude=length(u))
343 t_write+=dt_write
344 n_write+=1
345 t+=dt
346 n+=1
347
348 endtime = time.clock()
349 totaltime = endtime-starttime
350 global netotal
351 print ">>number of elements: %s, total time: %s, per time step: %s <<"%(netotal,totaltime,totaltime/n)
352 if __name__ =="__main__":
353 dom=getDomain()
354 rho,mu,lmbd,eta=getMaterialProperties(dom)
355 wavePropagation(dom,rho,mu,lmbd,eta)

  ViewVC Help
Powered by ViewVC 1.1.26