/[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 3892 - (show annotations)
Tue Apr 10 08:57:23 2012 UTC (6 years, 11 months ago) by jfenwick
File MIME type: text/x-python
File size: 4657 byte(s)
Merged changes across from the attempt2 branch.
This version builds and passes python2 tests.
It also passes most python3 tests.



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

  ViewVC Help
Powered by ViewVC 1.1.26