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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26