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

Revision 3195 - (show annotations)
Wed Sep 22 00:28:04 2010 UTC (9 years, 2 months ago) by ahallam
File MIME type: text/x-python
File size: 7560 byte(s)
```Shortened runtime of cookbook examples to aid testing.
```
 1 2 ######################################################## 3 # 4 # Copyright (c) 2009-2010 by University of Queensland 5 # Earth Systems Science Computational Center (ESSCC) 6 7 # 8 # Primary Business: Queensland, Australia 9 # Licensed under the Open Software License version 3.0 10 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 20 __url__= 21 22 ############################################################FILE HEADER 23 # example08b.py 24 # Antony Hallam 25 # Seismic Wave Equation Simulation using acceleration solution. 26 # Extend the solution in example 08a to use absorbing boundary 27 # conditions. 28 29 #######################################################EXTERNAL MODULES 30 from esys.escript import * 31 from esys.finley import Rectangle 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 44 ########################################################MPI WORLD CHECK 45 if getMPISizeWorld() > 1: 46 import sys 47 print "This example will not run in an MPI world." 48 sys.exit(0) 49 50 #################################################ESTABLISHING VARIABLES 51 # where to save output data 52 savepath = "data/example08b" 53 mkDir(savepath) 54 #Geometric and material property related variables. 55 mx = 1000. # model lenght 56 my = 1000. # model width 57 ndx = 300 # steps in x direction 58 ndy = 300 # steps in y direction 59 xstep=mx/ndx # calculate the size of delta x 60 ystep=abs(my/ndy) # calculate the size of delta y 61 lam=3.462e9 #lames constant 62 mu=3.462e9 #bulk modulus 63 rho=1154. #density 64 # Time related variables. 65 testing=True 66 if testing: 67 print 'The testing end time is curerntly sellected this severely limits the number of time iterations.' 68 print "Try changing testing to False for more iterations." 69 tend=0.001 70 else: 71 tend=0.5 # end time 72 73 h=0.0001 # time step 74 # data recording times 75 rtime=0.0 # first time to record 76 rtime_inc=tend/50.0 # time increment to record 77 #Check to make sure number of time steps is not too large. 78 print "Time step size= ",h, "Expected number of outputs= ",tend/h 79 80 U0=0.1 # amplitude of point source 81 ls=500 # length of the source 82 source=np.zeros(ls,'float') # source array 83 decay1=np.zeros(ls,'float') # decay curve one 84 decay2=np.zeros(ls,'float') # decay curve two 85 time=np.zeros(ls,'float') # time values 86 g=np.log(0.01)/ls 87 88 dfeq=50 #Dominant Frequency 89 a = 2.0 * (np.pi * dfeq)**2.0 90 t0 = 5.0 / (2.0 * np.pi * dfeq) 91 srclength = 5. * t0 92 ls = int(srclength/h) 93 print 'source length',ls 94 source=np.zeros(ls,'float') # source array 95 ampmax=0 96 for it in range(0,ls): 97 t = it*h 98 tt = t-t0 99 dum1 = np.exp(-a * tt * tt) 100 source[it] = -2. * a * tt * dum1 101 # source[it] = exp(-a * tt * tt) !gaussian 102 if (abs(source[it]) > ampmax): 103 ampmax = abs(source[it]) 104 #source[t]=np.exp(g*t)*U0*np.sin(2.*np.pi*t/(0.75*ls))*(np.exp(-.1*g*t)-1) 105 #decay1[t]=np.exp(g*t) 106 #decay2[t]=(np.exp(-.1*g*t)-1) 107 time[t]=t*h 108 #tdecay=decay1*decay2*U0 109 #decay1=decay1*U0; decay2=decay2*U0 110 pl.clf(); 111 pl.plot(source) 112 #pl.plot(time,decay1);pl.plot(time,decay2); 113 #pl.plot(time,tdecay) 114 pl.savefig(os.path.join(savepath,'source.png')) 115 116 # will introduce a spherical source at middle left of bottom face 117 xc=[mx/2,0] 118 119 ####################################################DOMAIN CONSTRUCTION 120 domain=Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy,order=2) # create the domain 121 x=domain.getX() # get the locations of the nodes in the domani 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=kmat*rho) #set the general form value D 130 131 ##########################################################ESTABLISH ABC 132 # Define where the boundary decay will be applied. 133 bn=50. 134 bleft=xstep*bn; bright=mx-(xstep*bn); bbot=my-(ystep*bn) 135 # btop=ystep*bn # don't apply to force boundary!!! 136 137 # locate these points in the domain 138 left=x[0]-bleft; right=x[0]-bright; bottom=x[1]-bbot 139 140 tgamma=0.85 # decay value for exponential function 141 def calc_gamma(G,npts): 142 func=np.sqrt(abs(-1.*np.log(G)/(npts**2.))) 143 return func 144 145 gleft = calc_gamma(tgamma,bleft) 146 gright = calc_gamma(tgamma,bleft) 147 gbottom= calc_gamma(tgamma,ystep*bn) 148 149 print 'gamma', gleft,gright,gbottom 150 151 # calculate decay functions 152 def abc_bfunc(gamma,loc,x,G): 153 func=exp(-1.*(gamma*abs(loc-x))**2.) 154 return func 155 156 fleft=abc_bfunc(gleft,bleft,x[0],tgamma) 157 fright=abc_bfunc(gright,bright,x[0],tgamma) 158 fbottom=abc_bfunc(gbottom,bbot,x[1],tgamma) 159 # apply these functions only where relevant 160 abcleft=fleft*whereNegative(left) 161 abcright=fright*wherePositive(right) 162 abcbottom=fbottom*wherePositive(bottom) 163 # make sure the inside of the abc is value 1 164 abcleft=abcleft+whereZero(abcleft) 165 abcright=abcright+whereZero(abcright) 166 abcbottom=abcbottom+whereZero(abcbottom) 167 # multiply the conditions together to get a smooth result 168 abc=abcleft*abcright*abcbottom 169 170 #visualise the boundary function 171 #abcT=abc.toListOfTuples() 172 #abcT=np.reshape(abcT,(ndx+1,ndy+1)) 173 #pl.clf(); pl.imshow(abcT); pl.colorbar(); 174 #pl.savefig(os.path.join(savepath,"abc.png")) 175 176 177 ############################################FIRST TIME STEPS AND SOURCE 178 # define small radius around point xc 179 src_length = 40; print "src_length = ",src_length 180 # set initial values for first two time steps with source terms 181 y=source[0]*(cos(length(x-xc)*3.1415/src_length)+1)*whereNegative(length(x-xc)-src_length) 182 src_dir=numpy.array([0.,1.]) # defines direction of point source as down 183 y=y*src_dir 184 mypde.setValue(y=y) #set the source as a function on the boundary 185 # initial value of displacement at point source is constant (U0=0.01) 186 # for first two time steps 187 u=[0.0,0.0]*wherePositive(x) 188 u_m1=u 189 190 ####################################################ITERATION VARIABLES 191 n=0 # iteration counter 192 t=0 # time counter 193 ##############################################################ITERATION 194 while t= rtime): 204 saveVTK(os.path.join(savepath,"ex08b.%05d.vtu"%n),displacement=length(u),\ 205 acceleration=length(accel),tensor=stress) 206 rtime=rtime+rtime_inc #increment data save time 207 # increment loop values 208 t=t+h; n=n+1 209 if (n < ls): 210 y=source[n]*(cos(length(x-xc)*3.1415/src_length)+1)*whereNegative(length(x-xc)-src_length) 211 y=y*src_dir; mypde.setValue(y=y) #set the source as a function on the boundary 212 print n,"-th time step t ",t

 ViewVC Help Powered by ViewVC 1.1.26