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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (show annotations)
Wed Feb 7 02:12:08 2018 UTC (7 months, 1 week ago) by jfenwick
File MIME type: text/x-python
File size: 7151 byte(s)
Make everyone sad by touching all the files

Copyright dates update

1 from __future__ import division, print_function
2 ##############################################################################
3 #
4 # Copyright (c) 2009-2018 by The University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Apache License, version 2.0
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2009-2018 by The University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Apache License, version 2.0
21 http://www.apache.org/licenses/LICENSE-2.0"""
22 __url__="https://launchpad.net/escript-finley"
23
24 ############################################################FILE HEADER
25 # example09.py
26 # Antony Hallam
27 # Seismic Wave Equation Simulation using acceleration solution.
28 # 3D model with multiple layers.
29
30 #######################################################EXTERNAL MODULES
31 import matplotlib
32 matplotlib.use('agg') #It's just here for automated testing
33 from esys.escript import *
34 from esys.weipa import saveVTK
35 import os
36 # smoothing operator
37 from esys.escript.pdetools import Projector, Locator
38 from esys.escript.unitsSI import *
39 import numpy as np
40
41 import pylab as pl
42 import matplotlib.cm as cm
43 from esys.escript.linearPDEs import LinearPDE, SolverOptions
44 try:
45 # This imports the rectangle domain function
46 from esys.finley import Rectangle, ReadMesh
47 HAVE_FINLEY = True
48 except ImportError:
49 print("Finley module not available")
50 HAVE_FINLEY = False
51 ########################################################MPI WORLD CHECK
52 if getMPISizeWorld() > 1:
53 import sys
54 print("This example will not run in an MPI world.")
55 sys.exit(0)
56
57 if HAVE_FINLEY:
58 #################################################ESTABLISHING VARIABLES
59 # where to save output data
60 savepath = "data/example09c"
61 meshpath = "data/example09n"
62 mkDir(savepath)
63 #Geometric and material property related variables.
64 domain=ReadMesh(os.path.join(savepath,'example09n.fly')) # create the domain
65 x=Solution(domain).getX()
66 #parameters layers 1,2,3,4 and fault
67 prho=np.array([2200.,2500.,3200.,4500.,5500.]) #density
68 pvel=np.array([1500.,2200.,3000.,3200.,5000.]) #velocity
69 pmu=pvel**2.*prho/4. #bulk modulus
70 plam=pvel**2.*prho/2. #lames constant
71 nlayers=4
72 width=300.0
73 rho=Scalar(0,Function(domain))
74 vel=Scalar(0,Function(domain))
75 mu=Scalar(0,Function(domain))
76 lam=Scalar(0,Function(domain))
77
78 print(0.5*np.sqrt(prho/(plam+2*pmu))*0.5)
79
80 for i in range(0,nlayers):
81 rho.setTaggedValue('lblock%d'%i,prho[i])
82 rho.setTaggedValue('rblock%d'%i,prho[i])
83 vel.setTaggedValue('lblock%d'%i,pvel[i])
84 vel.setTaggedValue('rblock%d'%i,pvel[i])
85 mu.setTaggedValue('lblock%d'%i,pmu[i])
86 mu.setTaggedValue('rblock%d'%i,pmu[i])
87 lam.setTaggedValue('lblock%d'%i,plam[i])
88 lam.setTaggedValue('rblock%d'%i,plam[i])
89 i=nlayers
90 rho.setTaggedValue('fault',prho[i])
91 vel.setTaggedValue('fault',pvel[i])
92 mu.setTaggedValue('fault',pmu[i])
93 lam.setTaggedValue('fault',plam[i])
94
95
96 # Time related variables.
97 testing=False
98 if testing:
99 print('The testing end time is currently selected. This severely limits the number of time iterations.')
100 print("Try changing testing to False for more iterations.")
101 tend=0.1
102 else:
103 tend=0.1 # end time
104
105 h=0.00001 # time step
106 # data recording times
107 rtime=0.0 # first time to record
108 rtime_inc=tend/750.0 # time increment to record
109 #Check to make sure number of time steps is not too large.
110 print("Time step size= ",h, "Expected number of outputs= ",tend/h)
111
112 U0=0.1 # amplitude of point source
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
118 ls = int(srclength/h)
119 print('source length',ls)
120
121 source=np.zeros(ls,'float') # source array
122 decay1=np.zeros(ls,'float') # decay curve one
123 decay2=np.zeros(ls,'float') # decay curve two
124 time=np.zeros(ls,'float') # time values
125 g=np.log(0.01)/ls
126
127 ampmax=0
128 for it in range(0,ls):
129 t = it*h
130 tt = t-t0
131 dum1 = np.exp(-a * tt * tt)
132 source[it] = -2. * a * tt * dum1
133 if (abs(source[it]) > ampmax):
134 ampmax = abs(source[it])
135 time[it]=t*h
136
137 # will introduce a spherical source at middle left of bottom face
138 xc=[150,0]
139
140 ##########################################################ESTABLISH PDE
141 mypde=LinearPDE(domain) # create pde
142 mypde.setSymmetryOn() # turn symmetry on
143 # turn lumping on for more efficient solving
144 mypde.getSolverOptions().setSolverMethod(SolverOptions.HRZ_LUMPING)
145 kmat = kronecker(domain) # create the kronecker delta function of the domain
146 mypde.setValue(D=rho*kmat) #set the general form value D
147
148 ############################################FIRST TIME STEPS AND SOURCE
149 # define small radius around point xc
150 src_length = 10; print("src_length = ",src_length)
151 # set initial values for first two time steps with source terms
152 xb=FunctionOnBoundary(domain).getX()
153 yx=(cos(length(xb-xc)*3.1415/src_length)+1)*whereNegative(length(xb-xc)-src_length)
154 stop=Scalar(0.0,FunctionOnBoundary(domain))
155 stop.setTaggedValue("top",1.0)
156 src_dir=numpy.array([0.,-1.]) # defines direction of point source as down
157
158 mypde.setValue(y=source[0]*yx*src_dir*stop) #set the source as a function on the boundary
159
160 # initial value of displacement at point source is constant (U0=0.01)
161 # for first two time steps
162 u=[0.0,0.0]*x
163 u_m1=u
164
165 ####################################################ITERATION VARIABLES
166 n=0 # iteration counter
167 t=0 # time counter
168 ##############################################################ITERATION
169 while t<tend:
170 # get current stress
171 g=grad(u); stress=lam*trace(g)*kmat+mu*(g+transpose(g))#*abc
172 mypde.setValue(X=-stress) # set PDE values
173 accel = mypde.getSolution() #get PDE solution for accelleration
174 u_p1=(2.*u-u_m1)+h*h*accel #calculate displacement
175 u_p1=u_p1#*abc # apply boundary conditions
176 u_m1=u; u=u_p1 # shift values by 1
177 # save current displacement, acceleration and pressure
178 if (t >= rtime):
179 saveVTK(os.path.join(savepath,"ex09c.%05d.vtu"%n),displacement=length(u),\
180 acceleration=length(accel),tensor=stress)
181 rtime=rtime+rtime_inc #increment data save time
182 # increment loop values
183 t=t+h; n=n+1
184 if (n < ls):
185 mypde.setValue(y=source[n]*yx*src_dir*stop) #set the source as a function on the boundary
186 print("time step %d, t=%s"%(n,t))

  ViewVC Help
Powered by ViewVC 1.1.26