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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3089 - (show annotations)
Mon Aug 9 07:20:58 2010 UTC (11 years, 1 month ago) by ahallam
File MIME type: text/x-python
File size: 6149 byte(s)
Updates to example scripts - should now be working except for example09b.py which needs more memory.
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 ############################################################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 import os
32 # smoothing operator
33 from esys.escript.pdetools import Projector, Locator
34 from esys.escript.unitsSI import *
35 import numpy as np
36 import pylab as pl
37 import matplotlib.cm as cm
38 from esys.escript.linearPDEs import LinearPDE
39 from esys.finley import ReadMesh
40
41 ########################################################MPI WORLD CHECK
42 if getMPISizeWorld() > 1:
43 import sys
44 print "This example will not run in an MPI world."
45 sys.exit(0)
46
47 #################################################ESTABLISHING VARIABLES
48 # where to save output data
49 savepath = "data/example09"
50 mkDir(savepath)
51 #Geometric and material property related variables.
52 mx = 200. # model lenght
53 my = 200. # model width
54 mz=100.0
55 step=10.0 # the element size
56 ndx = int(mx/step) # steps in x direction
57 ndy = int(my/step) # steps in y direction
58 ndz = int(mz/step)
59
60 vel2=1800.; vel1=3000.
61 rho2=2300.; rho1=3100. #density
62 mu2=vel2**2.*rho2/4.; mu1=vel1**2.*rho1/4. #bulk modulus
63 lam2=vel2**2.*rho2/2.; lam1=vel1**2.*rho1/2. #lames constant
64
65 # Time related variables.
66 tend=0.1 # end time
67 h=0.0001 # time step
68 # data recording times
69 rtime=0.0 # first time to record
70 rtime_inc=tend/50.0 # time increment to record
71 #Check to make sure number of time steps is not too large.
72 print "Time step size= ",h, "Expected number of outputs= ",tend/h
73
74 U0=0.1 # amplitude of point source
75 ls=500 # length of the source
76 source=np.zeros(ls,'float') # source array
77 decay1=np.zeros(ls,'float') # decay curve one
78 decay2=np.zeros(ls,'float') # decay curve two
79 time=np.zeros(ls,'float') # time values
80 g=np.log(0.01)/ls
81
82 dfeq=50 #Dominant Frequency
83 a = 2.0 * (np.pi * dfeq)**2.0
84 t0 = 5.0 / (2.0 * np.pi * dfeq)
85 srclength = 5. * t0
86 ls = int(srclength/h)
87 print 'source length',ls
88 source=np.zeros(ls,'float') # source array
89 ampmax=0
90 for it in range(0,ls):
91 t = it*h
92 tt = t-t0
93 dum1 = np.exp(-a * tt * tt)
94 source[it] = -2. * a * tt * dum1
95 if (abs(source[it]) > ampmax):
96 ampmax = abs(source[it])
97 time[t]=t*h
98 #tdecay=decay1*decay2*U0
99 #decay1=decay1*U0; decay2=decay2*U0
100 #pl.clf();
101 #pl.plot(source)
102 #pl.plot(time,decay1);pl.plot(time,decay2);
103 #pl.plot(time,tdecay)
104 #pl.savefig(os.path.join(savepath,'source.png'))
105
106 # will introduce a spherical source at middle left of bottom face
107 xc=[50,50,0]
108
109 ####################################################DOMAIN CONSTRUCTION
110 domain=ReadMesh(os.path.join(savepath,'example09m.fly')) # create the domain
111 x=domain.getX() # get the locations of the nodes in the domain
112
113 lam=Scalar(0,Function(domain))
114 lam.setTaggedValue("vintfa",lam1)
115 lam.setTaggedValue("vintfb",lam2)
116 mu=Scalar(0,Function(domain))
117 mu.setTaggedValue("vintfa",mu1)
118 mu.setTaggedValue("vintfb",mu2)
119 rho=Scalar(0,Function(domain))
120 rho.setTaggedValue("vintfa",rho1)
121 rho.setTaggedValue("vintfb",rho2)
122
123 ##########################################################ESTABLISH PDE
124 mypde=LinearPDE(domain) # create pde
125 mypde.setSymmetryOn() # turn symmetry on
126 # turn lumping on for more efficient solving
127 #mypde.getSolverOptions().setSolverMethod(mypde.getSolverOptions().LUMPING)
128 kmat = kronecker(domain) # create the kronecker delta function of the domain
129 mypde.setValue(D=rho*kmat) #set the general form value D
130
131 ############################################FIRST TIME STEPS AND SOURCE
132 # define small radius around point xc
133 src_length = 20; print "src_length = ",src_length
134 # set initial values for first two time steps with source terms
135 xb=FunctionOnBoundary(domain).getX()
136 #sy=source[0]*(cos(length(xb-xc)*3.1415/src_length)+1)*whereNegative(length(xb-src_length))
137 y=Vector(0.0,FunctionOnBoundary(domain))
138
139 src_dir=numpy.array([0.,0.,1.0]) # defines direction of point source as down
140
141 #sy=sy*src_dir
142 #sy.setTaggedValue("stop")
143 y.setTaggedValue("stop",src_dir*source[0])#)*(cos(length(xb-xc)*3.1415/src_length)+1))
144 mypde.setValue(y=y) #set the source as a function on the boundary
145 # initial value of displacement at point source is constant (U0=0.01)
146 # for first two time steps
147 u=[0.0,0.0,0.0]*wherePositive(x)
148 u_m1=u
149
150 ####################################################ITERATION VARIABLES
151 n=0 # iteration counter
152 t=0 # time counter
153 ##############################################################ITERATION
154 while t<tend:
155 # get current stress
156 g=grad(u); stress=lam*trace(g)*kmat+mu*(g+transpose(g))#*abc
157 mypde.setValue(X=-stress) # set PDE values
158 accel = mypde.getSolution() #get PDE solution for accelleration
159 u_p1=(2.*u-u_m1)+h*h*accel #calculate displacement
160 u_p1=u_p1#*abc # apply boundary conditions
161 u_m1=u; u=u_p1 # shift values by 1
162 # save current displacement, acceleration and pressure
163 if (t >= rtime):
164 saveVTK(os.path.join(savepath,"ex09.%05d.vtu"%n),displacement=length(u),\
165 acceleration=length(accel),tensor=stress)
166 rtime=rtime+rtime_inc #increment data save time
167 # increment loop values
168 t=t+h; n=n+1
169 if (n < ls):
170 y.setTaggedValue("stop",source[n]*src_dir)
171 mypde.setValue(y=y) #set the source as a function on the boundary
172 print n,"-th time step t ",t

  ViewVC Help
Powered by ViewVC 1.1.26