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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (hide annotations)
Wed Feb 7 02:12:08 2018 UTC (3 years, 5 months 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 sshaw 5288 from __future__ import division, print_function
2 jfenwick 3981 ##############################################################################
3 ahallam 3389 #
4 jfenwick 6651 # Copyright (c) 2009-2018 by The University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 ahallam 3389 #
7     # Primary Business: Queensland, Australia
8 jfenwick 6112 # Licensed under the Apache License, version 2.0
9     # http://www.apache.org/licenses/LICENSE-2.0
10 ahallam 3389 #
11 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 #
15     ##############################################################################
16 ahallam 3389
17 jfenwick 6651 __copyright__="""Copyright (c) 2009-2018 by The University of Queensland
18 jfenwick 3981 http://www.uq.edu.au
19 ahallam 3389 Primary Business: Queensland, Australia"""
20 jfenwick 6112 __license__="""Licensed under the Apache License, version 2.0
21     http://www.apache.org/licenses/LICENSE-2.0"""
22 ahallam 3389 __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 caltinay 4087 import matplotlib
32     matplotlib.use('agg') #It's just here for automated testing
33 ahallam 3389 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 sshaw 4821 from esys.escript.linearPDEs import LinearPDE, SolverOptions
44 sshaw 5288 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 ahallam 3389 ########################################################MPI WORLD CHECK
52     if getMPISizeWorld() > 1:
53 sshaw 4576 import sys
54     print("This example will not run in an MPI world.")
55     sys.exit(0)
56 ahallam 3389
57 sshaw 5288 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 ahallam 3389
78 sshaw 5288 print(0.5*np.sqrt(prho/(plam+2*pmu))*0.5)
79 ahallam 3389
80 sshaw 5288 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 ahallam 3389
95    
96 sshaw 5288 # 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 ahallam 3389
105 sshaw 5288 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 ahallam 3389
112 sshaw 5288 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 sshaw 5621
118 sshaw 5288 ls = int(srclength/h)
119     print('source length',ls)
120 sshaw 5621
121 sshaw 5288 source=np.zeros(ls,'float') # source array
122 sshaw 5621 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 sshaw 5288 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 sshaw 5621 time[it]=t*h
136 ahallam 3389
137 sshaw 5288 # will introduce a spherical source at middle left of bottom face
138     xc=[150,0]
139 ahallam 3389
140 sshaw 5288 ##########################################################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 ahallam 3389
148 sshaw 5288 ############################################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 ahallam 3389
158 sshaw 5288 mypde.setValue(y=source[0]*yx*src_dir*stop) #set the source as a function on the boundary
159 ahallam 3389
160 sshaw 5288 # 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 ahallam 3389
165 sshaw 5288 ####################################################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