/[escript]/branches/stage3.1/doc/examples/usersguide/wave.py
ViewVC logotype

Contents of /branches/stage3.1/doc/examples/usersguide/wave.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2945 - (show annotations)
Wed Feb 24 00:17:46 2010 UTC (9 years ago) by jfenwick
File MIME type: text/x-python
File size: 4274 byte(s)
Bringing release stage up to trunk version 2944

1
2 ########################################################
3 #
4 # Copyright (c) 2003-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) 2003-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 from esys.escript import *
23 from esys.escript.pdetools import Locator
24 from esys.escript.linearPDEs import LinearPDE
25 from esys.finley import Brick
26 from numpy import identity,zeros,ones
27 import matplotlib
28
29 matplotlib.use('agg') #For interactive use, you can comment out this line
30 #It's just here to make testing easier
31
32 import matplotlib.pyplot as plt
33
34
35 ne=32 # number of cells in x_0 and x_1 directions
36 width=10000. # length in x_0 and x_1 directions
37 lam=3.462e9
38 mu=3.462e9
39 rho=1154.
40 tend=10. # to ran a full simulation change tend to 60.
41 alpha=0.7
42 t0=3.
43
44
45 U0=1. # maximum displacement
46 mkDir("data") # create directory data if it does not exist already.
47
48 def wavePropagation(domain,h,tend,lam,mu,rho, xc, src_radius, U0):
49 # lists to collect displacement at point source
50 ts, u_pc0,u_pc1,u_pc2=[], [], [], []
51 x=domain.getX()
52 # ... open new PDE ...
53 mypde=LinearPDE(domain)
54 mypde.getSolverOptions().setSolverMethod(mypde.getSolverOptions().LUMPING)
55 kronecker=identity(mypde.getDim())
56
57 dunit=numpy.array([1.,0.,0.]) # defines direction of point source
58
59 mypde.setValue(D=kronecker*rho, q=whereNegative(length(x-xc)-src_radius)*dunit)
60 # ... set initial values ....
61 n=0
62 # for first two time steps
63 u=Vector(0.,Solution(domain))
64 u_last=Vector(0.,Solution(domain))
65 t=0
66
67 # define the location of the point source
68 L=Locator(domain,xc)
69 # find potential at point source
70 u_pc=L.getValue(u)
71 print "u at point charge=",u_pc
72 ts.append(t); u_pc0.append(u_pc[0]), u_pc1.append(u_pc[1]), u_pc2.append(u_pc[2])
73
74 while t<tend:
75 t+=h
76 # ... get current stress ....
77 g=grad(u)
78 stress=lam*trace(g)*kronecker+mu*(g+transpose(g))
79 # ... get new acceleration ....
80 amplitude=U0*(4*(t-t0)**3/alpha**3-6*(t-t0)/alpha)*sqrt(2.)/alpha**2*exp(1./2.-(t-t0)**2/alpha**2)
81 mypde.setValue(X=-stress, r=dunit*amplitude)
82 a=mypde.getSolution()
83 # ... get new displacement ...
84 u_new=2*u-u_last+h**2*a
85 # ... shift displacements ....
86 u_last=u
87 u=u_new
88 n+=1
89 print n,"-th time step t ",t
90 u_pc=L.getValue(u)
91 print "u at point charge=",u_pc
92 ts.append(t); u_pc0.append(u_pc[0]), u_pc1.append(u_pc[1]), u_pc2.append(u_pc[2])
93
94 # ... save current acceleration in units of gravity and displacements
95 if n==1 or n%10==0: saveVTK("./data/usoln.%i.vtu"%(n/10),acceleration=length(a)/9.81,
96 displacement = length(u), tensor = stress, Ux = u[0] )
97 return ts, u_pc0,u_pc1,u_pc2
98
99 #
100 # create domain:
101 #
102 mydomain=Brick(ne,ne,10,l0=width,l1=width,l2=10.*width/ne)
103 #
104 # sety time step size:
105 #
106 h=inf(1./5.)*inf(sqrt(rho/(lam+2*mu))*mydomain.getSize())
107 print "time step size = ",h
108 #
109 # spherical source at middle of bottom face
110 #
111 xc=[width/2.,width/2.,0.]
112 # define small radius around point xc
113 src_radius = 0.03*width
114 print "src_radius = ",src_radius
115 #
116 # run it
117 #
118 ts, u_pc0,u_pc1,u_pc2 = wavePropagation(mydomain,h,tend,lam,mu,rho, xc, src_radius, U0)
119 #
120 # create a plot:
121 #
122 if getMPIRankWorld() == 0:
123 plt.title("Displacement at Point Source")
124 plt.plot(ts, u_pc0, '-', label="x_0", linewidth=1)
125 plt.plot(ts, u_pc1, '-', label="x_1", linewidth=1)
126 plt.plot(ts, u_pc2, '-', label="x_2", linewidth=1)
127 plt.xlabel('time')
128 plt.ylabel('displacement')
129 plt.legend()
130 plt.savefig('u_pc.png', format='png')
131 # or save displacement
132 u_pc_data=FileWriter('./data/U_pc.out')
133 for i in xrange(len(ts)) :
134 u_pc_data.write("%f %f %f %f\n"%(ts[i],u_pc0[i],u_pc1[i],u_pc2[i]))
135 u_pc_data.close()
136

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/lapack2681/doc/examples/usersguide/wave.py:2682-2741 /branches/restext/doc/examples/usersguide/wave.py:2610-2624 /trunk/doc/examples/usersguide/wave.py:1388-2483,2872-2919,2924-2944

  ViewVC Help
Powered by ViewVC 1.1.26