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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4576 - (show annotations)
Mon Dec 9 23:35:30 2013 UTC (5 years, 9 months ago) by sshaw
File MIME type: text/x-python
File size: 4775 byte(s)
python3ified things, replaced mixed whitespace and xrange calls
1
2 ##############################################################################
3 #
4 # Copyright (c) 2009-2013 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development since 2012 by School of Earth Sciences
13 #
14 ##############################################################################
15
16 __copyright__="""Copyright (c) 2009-2013 by University of Queensland
17 http://www.uq.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __url__="https://launchpad.net/escript-finley"
22
23 ############################################################FILE HEADER
24 # example08a.py
25 # Antony Hallam
26 # Seismic Wave Equation Simulation using acceleration solution.
27
28 #######################################################EXTERNAL MODULES
29 from esys.escript import *
30 from esys.finley import Rectangle
31 from esys.weipa import saveVTK
32 import sys
33 import os
34 # smoothing operator
35 from esys.escript.pdetools import Projector, Locator
36 from esys.escript.unitsSI import *
37 import numpy as np
38 from esys.escript.linearPDEs import LinearPDE
39
40 ########################################################MPI WORLD CHECK
41 if getMPISizeWorld() > 1:
42 import sys
43 print("This example will not run in an MPI world.")
44 sys.exit(0)
45
46 #################################################ESTABLISHING VARIABLES
47 # where to save output data
48 savepath = "data/example08a"
49 mkDir(savepath)
50 #Geometric and material property related variables.
51 mx = 1000. # model lenght
52 my = -1000. # model width
53 ndx = 500 # steps in x direction
54 ndy = 500 # steps in y direction
55 xstep=mx/ndx # calculate the size of delta x
56 ystep=abs(my/ndy) # calculate the size of delta y
57 lam=3.462e9 #lames constant
58 mu=3.462e9 #bulk modulus
59 rho=1154. #density
60 # Time related variables.
61 testing=True
62 if testing:
63 print('The testing end time is currently selected. This severely limits the number of time iterations.')
64 print("Try changing testing to False for more iterations.")
65 tend=0.001
66 else:
67 tend=0.5 # end time
68
69 h=0.0005 # time step
70 # data recording times
71 rtime=0.0 # first time to record
72 rtime_inc=tend/20.0 # time increment to record
73 #Check to make sure number of time steps is not too large.
74 print("Time step size= ",h, "Expected number of outputs= ",tend/h)
75
76 U0=0.01 # amplitude of point source
77 # will introduce a spherical source at middle left of bottom face
78 xc=[mx/2,0]
79
80 ####################################################DOMAIN CONSTRUCTION
81 domain=Rectangle(l0=mx,l1=my,n0=ndx, n1=ndy) # create the domain
82 x=domain.getX() # get the locations of the nodes in the domani
83
84 ##########################################################ESTABLISH PDE
85 mypde=LinearPDE(domain) # create pde
86 mypde.setSymmetryOn() # turn symmetry on
87 # turn lumping on for more efficient solving
88 mypde.getSolverOptions().setSolverMethod(mypde.getSolverOptions().HRZ_LUMPING)
89 kmat = kronecker(domain) # create the kronecker delta function of the domain
90 mypde.setValue(D=kmat*rho) #set the general form value D
91
92 ############################################FIRST TIME STEPS AND SOURCE
93 # define small radius around point xc
94 src_length = 20; print("src_length = ",src_length)
95 # set initial values for first two time steps with source terms
96 y=U0*(cos(length(x-xc)*3.1415/src_length)+1)*whereNegative(length(x-xc)-src_length)
97 src_dir=numpy.array([0.,-1.]) # defines direction of point source as down
98 y=y*src_dir
99 mypde.setValue(y=y) #set the source as a function on the boundary
100 # initial value of displacement at point source is constant (U0=0.01)
101 # for first two time steps
102 u=[0.0,0.0]*whereNegative(x)
103 u_m1=u
104
105 ####################################################ITERATION VARIABLES
106 n=0 # iteration counter
107 t=0 # time counter
108 ##############################################################ITERATION
109 while t<tend:
110 # get current stress
111 g=grad(u); stress=lam*trace(g)*kmat+mu*(g+transpose(g))
112 mypde.setValue(X=-stress) # set PDE values
113 accel = mypde.getSolution() #get PDE solution for accelleration
114 u_p1=(2.*u-u_m1)+h*h*accel #calculate displacement
115 u_m1=u; u=u_p1 # shift values by 1
116 # save current displacement, acceleration and pressure
117 if (t >= rtime):
118 saveVTK(os.path.join(savepath,"ex08a.%05d.vtu"%n),displacement=length(u),\
119 acceleration=length(accel),tensor=stress)
120 rtime=rtime+rtime_inc #increment data save time
121 # increment loop values
122 t=t+h; n=n+1
123 print("time step %d, t=%s"%(n,t))

  ViewVC Help
Powered by ViewVC 1.1.26