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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4005 - (hide annotations)
Fri Sep 28 06:09:03 2012 UTC (8 years, 9 months ago) by caltinay
File MIME type: text/x-python
File size: 4723 byte(s)
test fixes, doco updates, annoyance removals.

1 ahallam 3025
2 jfenwick 3981 ##############################################################################
3 ahallam 3025 #
4 jfenwick 3911 # Copyright (c) 2009-2012 by University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 ahallam 3025 #
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 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12     # Development since 2012 by School of Earth Sciences
13     #
14     ##############################################################################
15 ahallam 3025
16 jfenwick 3911 __copyright__="""Copyright (c) 2009-2012 by University of Queensland
17 jfenwick 3981 http://www.uq.edu.au
18 ahallam 3025 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 ahallam 3029 # example08a.py
25 ahallam 3025 # 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 caltinay 3346 from esys.weipa import saveVTK
32 ahallam 3025 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 ahallam 3195 ########################################################MPI WORLD CHECK
41     if getMPISizeWorld() > 1:
42     import sys
43 jfenwick 3892 print("This example will not run in an MPI world.")
44 ahallam 3195 sys.exit(0)
45    
46 ahallam 3025 #################################################ESTABLISHING VARIABLES
47     # where to save output data
48 ahallam 3029 savepath = "data/example08a"
49 ahallam 3025 mkDir(savepath)
50     #Geometric and material property related variables.
51     mx = 1000. # model lenght
52     my = -1000. # model width
53 ahallam 3065 ndx = 500 # steps in x direction
54     ndy = 500 # steps in y direction
55 ahallam 3025 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 ahallam 3195 testing=True
62     if testing:
63 jfenwick 3892 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 ahallam 3195 tend=0.001
66     else:
67     tend=0.5 # end time
68    
69 ahallam 3065 h=0.0005 # time step
70 ahallam 3029 # data recording times
71     rtime=0.0 # first time to record
72     rtime_inc=tend/20.0 # time increment to record
73 ahallam 3025 #Check to make sure number of time steps is not too large.
74 jfenwick 3892 print("Time step size= ",h, "Expected number of outputs= ",tend/h)
75 ahallam 3025
76     U0=0.01 # amplitude of point source
77     # will introduce a spherical source at middle left of bottom face
78 ahallam 3065 xc=[mx/2,0]
79 ahallam 3025
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 ahallam 3389 mypde.getSolverOptions().setSolverMethod(mypde.getSolverOptions().HRZ_LUMPING)
89 ahallam 3025 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 jfenwick 3892 src_length = 20; print("src_length = ",src_length)
95 ahallam 3025 # set initial values for first two time steps with source terms
96 ahallam 3029 y=U0*(cos(length(x-xc)*3.1415/src_length)+1)*whereNegative(length(x-xc)-src_length)
97 ahallam 3025 src_dir=numpy.array([0.,-1.]) # defines direction of point source as down
98 ahallam 3029 y=y*src_dir
99 ahallam 3025 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 ahallam 3029 saveVTK(os.path.join(savepath,"ex08a.%05d.vtu"%n),displacement=length(u),\
119     acceleration=length(accel),tensor=stress)
120 ahallam 3025 rtime=rtime+rtime_inc #increment data save time
121     # increment loop values
122     t=t+h; n=n+1
123 caltinay 4005 print("time step %d, t=%s"%(n,t))

  ViewVC Help
Powered by ViewVC 1.1.26